PDA

Click to See Complete Forum and Search --> : Database Location Hardset?


greysquirl
Oct 12th, 2000, 11:07 AM
I have a program that I have written in VB6. My problem is this, when others install the program it looks to my hard drive on the network for the database because in the prog it is hard set. How do I fix this problem? What I want to be able to do is install the prog into any folder and as long as the db file is in the same folder it should start up.

JazzBass
Oct 12th, 2000, 11:19 AM
Hi,
Try using app.path. Sounds like what you need.

Check out this code:



Sub FindDBPath

dim sDBPath as string

If right$(app.path, 1) = "\" then
sDBPath = app.path & "your database name here"
Else
sDBPath = app.path & "\your database name here"
End IF

End Sub



Hope that helps.

Jazzbass

greysquirl
Oct 12th, 2000, 11:21 AM
Thanks for the code. I only have one more question. . .where shoud I insert this code at? Anywhere I have an adodc?

JazzBass
Oct 12th, 2000, 11:34 AM
Your welcome for the code,

As to you question:

Well, it depends. Do you have a routine that finds Public variables when you program is first open. I use this code in all of my programs that require some sort of file use.

You could put it at every place you ADO, but what I would do is paste the above code into a module and declare the variable sDBPath as Public in the General Declarations of the Module.

I know some here do not like to use Public Variables, but I do and seem to work fine for me.

Anymore ?'s, please ask.

JazzBass

greysquirl
Oct 12th, 2000, 11:45 AM
I created a new module and inserted the code like you said. I am still having this problem though. I have several screens in my program, each one has an Adodc in it. On each one of the Adodc's there is a Connection String that looks to the database. How can I make it not look to the database and look to the module? Also, in your code where it says "your database name here" should I just put. . . eiss.mdb (this is the name of my Db); or should I put the final destination of the file?

JazzBass
Oct 12th, 2000, 11:57 AM
OK,

I'm sorry. I left something out.


"Your Database Here" Question,

Yes replace this with the name of your database


To Find the location of the database


When your first form loads, under the Form_Load event, call the sub like this.



FindDBPath



Make sure your variable sDBPath is Declared Public in the Genernal Declarations of your module.

Now, in your connection string, for the path and name of your database, just put in "sDBPath" without the quotes.
Repeat this for all connections you need to make.

Since you ran the Sub FindDBPath right when your program starts, this variable will be avaliable anywhere in your program.

Make sure when you exit your program, before the "End" command, type in this code.



sDBPath = ""



Whatever memory this variable takes up, is now free.

Hope I explained it OK. If you need further help, post you code and make changes if you would like.

JazzBass

JazzBass
Oct 12th, 2000, 12:31 PM
greysquirl,

Just wanted to let you know I'm leaving for the day and I won't be able to check the board until tomorrow.

Hope the help is what you needed.

JazzBass