CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Path problem

  1. #1
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    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 "\".

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    You seem to be wanting two conflicting things...

    1) The location of the mdb/exe file
    2) the root directory.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210
    do you need something like this ?
    App.Path + "\" + "file.mdb"

  4. #4
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    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.

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    hspc previously posted that answer....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #6
    Join Date
    Apr 2004
    Location
    Austria
    Posts
    43
    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

  7. #7
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20
    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.

  8. #8
    Join Date
    Apr 2004
    Location
    Austria
    Posts
    43
    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

  9. #9
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    Smile 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured