Settine the DB path within the DOT template

D

Daniel Caron

Good Day to all.

Coming from the VB6 world, I am being confronted with a dilemna here.

When running my template from within the VBA IDE, there is no problem at all
to open my database like this

Set dbPars = OpenDatabase(ActiveDocument.Path & "\" & "pars.mdb")
Set rsPars = dbPars.OpenRecordset("PARS").

But the DB is in another directory on my HD. I need to know to code the path
of my DB so it can be anywhere on my HD.

And also I need to know where in the DOT I should put that code, in a module
? in the Userform_Initialize ? I want to make sure that it will get loaded
flawlessly when opening the DOT file.

Regards to all

Daniel
 
P

Perry

Store the pathname in a intermediaire file, such as an INI file.
Pseudo code to retrieve the DB path from Word VBA:

Snippet of file: c:\Temp\MyIniFile.INI
=start snip
[Database]
Path=y:\Data\Anypath\
Name=MyDatabase.MDB
=end snip

Retrieving info in Word:
=start Word VBA code
Dim sINI as string
Dim sPath as string
Dim sDBName as string
sINI = "c:\Temp\MyIniFile.INI"
sPath = System.PrivateProfilestring(sINI, "Database", "Path")
sDBName = System.PrivateProfilestring(sINI, "Database", "Name")
MsgBox "My database path is: " sPath & vbCr & _
"FileName: " & sDBName & vbCr & "DB FullFileName: " & vbCr & _
sPath & sDBName

=end Word VBA code

Krgrds,
Perry
 
D

Daniel Caron

Thank You once again Perry for your help. It's an alternative. I though that
you could say something like app.path. In VB6 it is easy.

Regards


Perry said:
Store the pathname in a intermediaire file, such as an INI file.
Pseudo code to retrieve the DB path from Word VBA:

Snippet of file: c:\Temp\MyIniFile.INI
=start snip
[Database]
Path=y:\Data\Anypath\
Name=MyDatabase.MDB
=end snip

Retrieving info in Word:
=start Word VBA code
Dim sINI as string
Dim sPath as string
Dim sDBName as string
sINI = "c:\Temp\MyIniFile.INI"
sPath = System.PrivateProfilestring(sINI, "Database", "Path")
sDBName = System.PrivateProfilestring(sINI, "Database", "Name")
MsgBox "My database path is: " sPath & vbCr & _
"FileName: " & sDBName & vbCr & "DB FullFileName: " & vbCr & _
sPath & sDBName

=end Word VBA code

Krgrds,
Perry

Daniel Caron said:
Good Day to all.

Coming from the VB6 world, I am being confronted with a dilemna here.

When running my template from within the VBA IDE, there is no problem at all
to open my database like this

Set dbPars = OpenDatabase(ActiveDocument.Path & "\" & "pars.mdb")
Set rsPars = dbPars.OpenRecordset("PARS").

But the DB is in another directory on my HD. I need to know to code the path
of my DB so it can be anywhere on my HD.

And also I need to know where in the DOT I should put that code, in a module
? in the Userform_Initialize ? I want to make sure that it will get
loaded
flawlessly when opening the DOT file.

Regards to all

Daniel
 
D

Daniel Caron

Thanks..it did the trick.

Daniel

Gossh...I love this newsgroup.

Perry said:
Store the pathname in a intermediaire file, such as an INI file.
Pseudo code to retrieve the DB path from Word VBA:

Snippet of file: c:\Temp\MyIniFile.INI
=start snip
[Database]
Path=y:\Data\Anypath\
Name=MyDatabase.MDB
=end snip

Retrieving info in Word:
=start Word VBA code
Dim sINI as string
Dim sPath as string
Dim sDBName as string
sINI = "c:\Temp\MyIniFile.INI"
sPath = System.PrivateProfilestring(sINI, "Database", "Path")
sDBName = System.PrivateProfilestring(sINI, "Database", "Name")
MsgBox "My database path is: " sPath & vbCr & _
"FileName: " & sDBName & vbCr & "DB FullFileName: " & vbCr & _
sPath & sDBName

=end Word VBA code

Krgrds,
Perry

Daniel Caron said:
Good Day to all.

Coming from the VB6 world, I am being confronted with a dilemna here.

When running my template from within the VBA IDE, there is no problem at all
to open my database like this

Set dbPars = OpenDatabase(ActiveDocument.Path & "\" & "pars.mdb")
Set rsPars = dbPars.OpenRecordset("PARS").

But the DB is in another directory on my HD. I need to know to code the path
of my DB so it can be anywhere on my HD.

And also I need to know where in the DOT I should put that code, in a module
? in the Userform_Initialize ? I want to make sure that it will get
loaded
flawlessly when opening the DOT file.

Regards to all

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top