-
Path problem
hy!
I'm having a little trouble with the paths in my vb6 program. I'm working with access files *.mdb and I don't know how to make the program to set the default path to the directory where the *.exe and the *.mdb files are stored.
I want to set the path to "\".
-
You seem to be wanting two conflicting things...
1) The location of the mdb/exe file
2) the root directory.
-
do you need something like this ?
App.Path + "\" + "file.mdb"
-
A little more details
My files (*.exe and *.mdb) are stored in one place (in one directory) "E:\--- My Documents ---\Gestiune stoc\".
VB by default set up the path to that directory for the mdb files, e.g. "E:\--- My Documents ---\Gestiune stoc\stoc.mdb".
If i move the *.exe file (the project) and the *.mdb files in another directory, let's say "E:\Temp" and run the exe program it will display an error saying that the *.mdb files were not found in the old path("E:\--- My Documents ---\Gestiune stoc\"). I want to set up the program to look up these files in the current directory not the old one. Something like a dinamic path.
-
hspc previously posted that answer....
-
App.Path returns you the current working directory
But please note. You should check if the app.path returns a \ at the end.
if you place the exe in C:\
App.path will be "C:\"
if you place it in c:\temp\
App.path will be "C:\temp" without the terminating \
So just check with mid$ the last character for \ ..
ah.. and you problem is solved by:
Code:
App.Path & "\stoc.mdb"
as TheCPUWizard said before
greetings UNI
-
Oki, so one of my problem was solved with the App.Path + "\" + "file.mdb" . i'm now able to open a *.mdb file located in the same directory with the *.exe file.
I have another problem with the paths that bugs me. It's about the connection string where it is given the path to the *.mdb files. It looks like this:
PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=E:\--- My Documents ---\Gestiune stoc\clienti.mdb;
If i let it like this the program will run whithout errors only from the directory mentioned, "E:\--- My Docu......".
If i modify the connection string to:
PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=clienti.mdb;
the program will not run in design mode (when i press F5), displaying file not found errors, referring to the *.mdb. But after compiling the program will run from any location.
So if other solution I'll run the program from a specific directory and I'll modify the path only when i make the final compiling solving the problem.
-
maybe you should try thinking about assembling strings?
The connection string is a string that can be created like we did with the app.path
strConn = "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" & App.Path & "\clienti.mdb;"
You can also replace app.path by the content of a Textbox (textbox1.text) etc.. everything that is a string.
greetings UNI
-
I've solved it!!!
I've tried a little bit with the assembly but it didn't work. Instead i've modified the connection string from the ADODC Proprieties for the control of the *.mdb file. I've erased the static path (e.g. "E:\--- My Do....") and left only the file name. There is a button that tests the connection, and the connection was ok. Now the exe file and the mdb files can be in any directory and the program will work. Also in design mode i can access the *.mdb files. So everything is fine now.
Thanks for the help everyone. :wave: