|
-
Jul 25th, 2008, 03:05 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] What is wrong with this ADO statement
I need to be flexible when I open the mdb at customer sites. The line that is commented out works fine but the one I am trying under it errors:
Code:
Option Explicit
'Private Const CNXSTRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Aces Projects\GL\database\AcesGL.mdb;Persist Security Info=False"
Private Const CNXSTRING = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\database\AcesGL.mdb;Persist Security Info=False"
Private cnx As ADODB.Connection
Private rs As ADODB.Recordset
Private aRs As ADODB.Recordset
Private Prs As ADODB.Recordset
I am following a textbook; however, I get an error saying:
"Constant Expression Required"
App.Path is correct and has a value of "C:\Aces Projects\GL"
Thanks in advance for help.
-
Jul 25th, 2008, 03:09 PM
#2
Re: What is wrong with this ADO statement
change
Code:
Private Const CNXSTRING = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\database\AcesGL.mdb;Persist Security Info=False"
to
Code:
Private CNXSTRING as string= "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\database\AcesGL.mdb;Persist Security Info=False"
__________________
Rate the posts that helped you 
-
Jul 25th, 2008, 03:10 PM
#3
Re: What is wrong with this ADO statement
as you can not concatenate two string in declaration if variable is of type CONST
__________________
Rate the posts that helped you 
-
Jul 25th, 2008, 03:35 PM
#4
Thread Starter
Hyperactive Member
Re: What is wrong with this ADO statement
Sorry, it still gives me an error. It now highlights the "=" and says "expected end of statement". I think I copied it correctly:
Code:
Private CNXSTRING as string= "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\database\AcesGL.mdb;Persist Security Info=False"
-
Jul 25th, 2008, 03:40 PM
#5
Re: What is wrong with this ADO statement
not sure what went wrong but just give one more try with below
Code:
Private CNXSTRING as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database\AcesGL.mdb;Persist Security Info=False"
__________________
Rate the posts that helped you 
-
Jul 25th, 2008, 03:46 PM
#6
Thread Starter
Hyperactive Member
Re: What is wrong with this ADO statement
-
Jul 25th, 2008, 03:48 PM
#7
Re: What is wrong with this ADO statement
what language you are using?is it vb.net?
__________________
Rate the posts that helped you 
-
Jul 25th, 2008, 03:52 PM
#8
Thread Starter
Hyperactive Member
Re: What is wrong with this ADO statement
-
Jul 25th, 2008, 03:58 PM
#9
Re: What is wrong with this ADO statement
ok,not very much familiar with vb6 syntax but one of below should work..
Code:
dim CNXSTRING as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database\AcesGL.mdb;Persist Security Info=False"
or
Code:
dim CNXSTRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database\AcesGL.mdb;Persist Security Info=False"
__________________
Rate the posts that helped you 
-
Jul 25th, 2008, 04:21 PM
#10
Thread Starter
Hyperactive Member
Re: What is wrong with this ADO statement
I got it working with some help. I had to declare the variable first. I then loaded the concatenated value to it separately and it now works! Thanks for responding.
-
Jul 25th, 2008, 04:38 PM
#11
Re: [RESOLVED] What is wrong with this ADO statement
Glad to know your problem is solved,it would be good if you can post your solution so it can be helpfull to someone else in future
__________________
Rate the posts that helped you 
-
Jul 25th, 2008, 04:53 PM
#12
Thread Starter
Hyperactive Member
Re: [RESOLVED] What is wrong with this ADO statement
Well, this does work if you "hardwire" the database location:
Code:
'Private Const CNXSTRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\GL.mdb;Persist Security Info=False"
This does not work but I am not sure why. It has something to do with value restrictions I was told.
[CODE]
Private CNXSTRING as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database\AcesGL.mdb;Persist Security Info=False"
[CODE]
So, to make it work, in the top of the form, I put:
Code:
Private CNXSTRING As String
And in the form_Initialize routine I put this"
Code:
Set cnx = New ADODB.Connection
CNXSTRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database\AcesGL.mdb;Persist Security Info=False"
cnx.Open CNXSTRING
Hope this helps someone.
-
Jul 26th, 2008, 08:14 AM
#13
Re: [RESOLVED] What is wrong with this ADO statement
That behaviour is expected..
App.Path is not a fixed value (it can change each time you run the program), so is not a constant value - and therefore the compiler cannot hard-code it.
In Classic VB you cannot declare and set a variable in one line of code, you need to use separate declaration and assignment statements (but Consts are the opposite).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|