Visual Basic Connection String

  • Thread starter Thread starter Wzd
  • Start date Start date

Wzd

Wzd

Associate
Joined
26 Feb 2004
Posts
994
Location
London
Hi there!

Can anyone help me out with a little problem im having with Visual Basic in Access? I'm kinda new to it so i dont know if this is possible, but can you write a connection string without specifying the exact path??

My current code is:
Code:
Const dbfile = "c:\test\test.mdb"
Const strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile & ";Persist Security Info=False"

What i want to do is just specify the file name incase i move it to a different directory, because i dont want to have to keep changing the code each time. If i take out c:\test\ it looks for the file in myDocuments! I've tried using the Path command but it keeps coming back saying "constant required"

Anyone have any ideas??

Thanks
 
If you want to use that connection method then you need to fully specify the path to the mdb file. Have you considered using an enviroment variable or storing the location in the registry so that you can change to location on a per install basis without having to hard code it into the source?

HT
 
ok dumb me, spent all afternoon yesterday looking for the solution when it was looking me in the face...i just had to remove the 'Const' from the begining of each line, works as follows now...

Code:
dbfile = CurrentProject.Path & "\test.mdb"
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile & ";Persist Security Info=False"

That'll teach me to copy/paste code from websites :rolleyes:
 
Back
Top Bottom