question about opening a doc in Word

pauly

Registered User.
Local time
Today, 05:48
Joined
Jul 8, 2002
Messages
49
I am wanting to open some documents that exist on disk so that they can be printed when required. The problem is that i have to hard code the file locations, the problem with this is when the database is finished the files will no longer exist in the directory path coded, is there a way to specify which file to open without specifying the full path?
below is my code

Dim loc As String, str As String
loc = "C:\Paul\Third Year\ie\database\ucc\blankforms\"
Dim myObject As Word.Application
Set myObject = CreateObject("Word.Application")
str = loc & "RegistrationForm.doc"
myObject.Documents.Open str, , True
 
This is the kind of situation where I would store the value in a table holding 'fundamental' variables. Easy to update values. No code maintenance.
TblSystem
- SystValueID (AutonumberPK)
- SystValueName (Text)
- SystValueDescription (text)

Store/update values through a 'system' form / recordsets / queries
Retrieve values using Dlookup
 
You might store the DOC file inside a table thus becoming completely independant. The only problem is the bloating effect, in order to avoid it you need a special wizard like Word!with ACCESS.
 
I havent worked out how to specify without the path. But if you know that the files will be located near your database then to get the db path try:
Dim db as Database, path as String
set db = CurrentDB
path = db.Name

and then if you could use Left() to remiove the db file name and you have the file path of your database
 
How I have done it is to store the documents in a subfolder of my back end database then using code, determine the path of my backend, add on "Docs/" then open the file.
Another way you could do it is using the filesearch command (Application.FileSearch) to find the document for you (it means knowing the name of the document mind you or using wildcards eg "*.doc") and then automatically open it.
 
Is the reason that you don't know the location of the files is that when this goes into production the files will be moved?

If the files are located in the same directory as the database, or in a subdirectory thereof, you can locate the database's directory with some code. (You were already using VBA so I'm not afraid to suggest this option.)

You can locate the database itself with

Dim dbCur as Database
Dim stDBName as String


Set dbCur = CurrentDB
stDBName = dbCur.Name

This will be the full path to your database.

If the files are in a directory related to this database, you can parse this name to find the path, then tack on whatever else you need in order to find the files.

In the case of a split database, the links to the tables can be read as a property of the table, thus again giving you a partial path.

If the files will be in the directory or subdirectory of any part of your database, you could find them that way.
 

Users who are viewing this thread

Back
Top Bottom