Path to Database 
Author Message
 Path to Database

I expexct this question has been asked before but I have failed to find the
answer. Any help would be appreciated.
When I compile my prg. and install it to on another computer the prg. looks
for my .MDB files in the same path as it was compiled from on my computer.
I need to know how to get the path that my prg. was executed from and then
set the path of the .MDB file to same path.  I hope this makes sense to some
one.

Any help would truly be appreciated....

Thanks

...Tom



Thu, 17 May 2001 03:00:00 GMT  
 Path to Database
Tom,

I suggest that you use an ini file (or the registry) to store (on each user
machine) the path for their .MDB file.  When the program starts, one of its
first tasks should be to interrogate the ini file (or registry as
appropriate) to find the location of the database on this particular
machine.  Use the path supplied to open the database (i.e. use something
like OpenDatabase(g_strDBLocation) rather than
OpenDatabase("c:\projects\myprojects\MyDb.mdb")

To access ini files is pretty easy, in case you haven't played around with
this sort of stuff before I give an general outline of the process below:

Suppose you created an ini file called MyIniFile.Ini and placed it in the
Windows directory.  This file might simply contain the following:

[Main]
DB Location=j:\Central\Database

assuming that user had the network drive mapped to "j" on this particular
machine (or a network path or whatever).  You could then retrieve this value
using code similar to the following:

Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As
String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Declare Function GetWindowsDirectory Lib "kernel32" Alias
"GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As
Long

Function GetDatabaseLocation() as String
  Dim StrRet$
  Dim lRet&
  dim IniFileName$

  StrRet$ = Space$(100)
  lRet& = GetWindowsDirectory(StrRet$, Len(StrRet$))
  If lRet& <= 0 Then
    MsgBox "Unable to locate key system files.  Unable to continue"
    Exit Sub
  End If

  IniFileName$ = Left$(StrRet$, lRet&)
  IniFileName$ = IniFileName$ + "\MyIniFile.Ini"

  StrRet$ = Space$(100)
  lRet& = GetPrivateProfileString("Main", "DB Location", "UNKNOWN", StrRet$,
Len(StrRet$), InifileName$)
  StrRet$ = Left$(StrRet$, lRet&)
  If StrRet$ = "UNKNOWN" Then
    MsgBox "Key system files have become corrupted.  Unable to continue"
    Exit Sub
  End If

  GetDatabaseLocation = StrRet$ + "\mydb.mdb"
end function

BTW if you are certain that the windows directory is always going the be
"c:\windows" you could dispense with the variable IniFileName$ and just
hard-code the ini file name as "c:\windows\myinifile.ini".

Using this approach, if you change the database location (or a different
user uses the j drive for another mapping) all you need to do is edit the
ini file (using notepad or something similar) and you're done - no recompile
required!

HTH

Peter

As an old-fashioned guy, I find ini files somewhat easier to work with than
the registry

Quote:

>I expexct this question has been asked before but I have failed to find the
>answer. Any help would be appreciated.
>When I compile my prg. and install it to on another computer the prg. looks
>for my .MDB files in the same path as it was compiled from on my computer.
>I need to know how to get the path that my prg. was executed from and then
>set the path of the .MDB file to same path.  I hope this makes sense to
some
>one.

>Any help would truly be appreciated....

>Thanks

>...Tom



Thu, 17 May 2001 03:00:00 GMT  
 Path to Database
Thanks a bunch Peter.  I will give it a whirl.  Some of it is greek to me
but I am game for trying anthing.
If you don't here from me in a week send for more coffee.. <G>

Quote:

>Tom,

>I suggest that you use an ini file (or the registry) to store (on each user
>machine) the path for their .MDB file.  When the program starts, one of its
>first tasks should be to interrogate the ini file (or registry as
>appropriate) to find the location of the database on this particular
>machine.  Use the path supplied to open the database (i.e. use something
>like OpenDatabase(g_strDBLocation) rather than
>OpenDatabase("c:\projects\myprojects\MyDb.mdb")

>To access ini files is pretty easy, in case you haven't played around with
>this sort of stuff before I give an general outline of the process below:

>Suppose you created an ini file called MyIniFile.Ini and placed it in the
>Windows directory.  This file might simply contain the following:

>[Main]
>DB Location=j:\Central\Database

>assuming that user had the network drive mapped to "j" on this particular
>machine (or a network path or whatever).  You could then retrieve this
value
>using code similar to the following:

>Declare Function GetPrivateProfileString Lib "kernel32" Alias
>"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
>lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As
>String, ByVal nSize As Long, ByVal lpFileName As String) As Long

>Declare Function GetWindowsDirectory Lib "kernel32" Alias
>"GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As
>Long

>Function GetDatabaseLocation() as String
>  Dim StrRet$
>  Dim lRet&
>  dim IniFileName$

>  StrRet$ = Space$(100)
>  lRet& = GetWindowsDirectory(StrRet$, Len(StrRet$))
>  If lRet& <= 0 Then
>    MsgBox "Unable to locate key system files.  Unable to continue"
>    Exit Sub
>  End If

>  IniFileName$ = Left$(StrRet$, lRet&)
>  IniFileName$ = IniFileName$ + "\MyIniFile.Ini"

>  StrRet$ = Space$(100)
>  lRet& = GetPrivateProfileString("Main", "DB Location", "UNKNOWN",
StrRet$,
>Len(StrRet$), InifileName$)
>  StrRet$ = Left$(StrRet$, lRet&)
>  If StrRet$ = "UNKNOWN" Then
>    MsgBox "Key system files have become corrupted.  Unable to continue"
>    Exit Sub
>  End If

>  GetDatabaseLocation = StrRet$ + "\mydb.mdb"
>end function

>BTW if you are certain that the windows directory is always going the be
>"c:\windows" you could dispense with the variable IniFileName$ and just
>hard-code the ini file name as "c:\windows\myinifile.ini".

>Using this approach, if you change the database location (or a different
>user uses the j drive for another mapping) all you need to do is edit the
>ini file (using notepad or something similar) and you're done - no
recompile
>required!

>HTH

>Peter

>As an old-fashioned guy, I find ini files somewhat easier to work with than
>the registry



Thu, 17 May 2001 03:00:00 GMT  
 Path to Database
If you can always guarentee that the database will be found on the same
directory as the executable, and if the user on the lan will always have
read/write access to the database file, you can use the app object to
determine the path to the executable.  So the reference would be something
like:
    sDBName = App.Path & "\MyDb.MDB"

Have fun...
--Doug

Quote:

>I expexct this question has been asked before but I have failed to find the
>answer. Any help would be appreciated.
>When I compile my prg. and install it to on another computer the prg. looks
>for my .MDB files in the same path as it was compiled from on my computer.
>I need to know how to get the path that my prg. was executed from and then
>set the path of the .MDB file to same path.  I hope this makes sense to
some
>one.

>Any help would truly be appreciated....

>Thanks

>...Tom



Thu, 17 May 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to get path to database

2. Savung image file path to database

3. default path and databases

4. Setting path to database from text file ??

5. How to set path for database (.mdb) file ???

6. Putting a picture in a report, but getting just the path from database

7. How to find path to database before invoking OpenDatabase

8. How to get full path to database file?

9. path to database with ADODC

10. Dynamic Path to Database/ADO Controls

11. Change in System DSN path to Database?

12. Changing the path for database (*.MDB) after install (VB5 & CR6)

 

 
Powered by phpBB® Forum Software