relative path reference

Z

zxcv

Hi,
I created a Word user form that fills in data from an Access database. In
order for the linkage to be successful, I had to create a reference to the
database from within Word. This works fine when I specify an *absolute*
reference to the file, but the problem is I can't get a *relative* reference
to work. A relative reference is really what I need, because I want to give
this user form to other people working on other computers.

I put both the Access and Word files in the *same* folder, so I though that
I could simply enter the file name with no other path information (e.g.,
Datafile.mdb), and Windows would automatically assume the file is in the same
folder as the Word file, but I get a runtime error (3024, Could not find the
file).

Could someone explain to me how to successfully create a relative reference?

Thank you,
 
Z

zxcv

Actually, I just figured out a way to make it work using the Document.path
property. But I'm still curious as to why the simple file reference
Datafile.mdb didn't work, considering that I put the Word and Access files in
the exact same directory.
 
H

heureux-oli

Hi,

May be an idea, if you use ActiveDocument.Path, you will get the path of the
document. After a concatenation with the db filename, I think that it would
be fine.



--
Heureux-oli
Si rien n'est mentionné pour le code, c'est que j'en suis l'auteur.
http://heureuxoli.developpez.com/
http://word.developpez.com/

----------------------------------------------------------------------------------
 
D

David Horowitz

Dear cxcv (interesting name!):
Would you reply with at a minimum the line of code you are using to connect
to the Access database? I assume we're talking about ADO, but we should find
out. OLEDB or ODBC, etc. too - your connection string.
On the other hand, no matter how you're connecting to the DB, you should be
able to make use of the ActiveDocument.Path property, which will give the
folder location of the Word document you're in. Then you can append a
backslash and the name of the Access db, as in:
strRelativeFilename = "theAccessFile.mdb"
strAbsoluteFilename = ActiveDocument.Path & "\" & strRelativeFilename
 
D

Doug Robbins - Word MVP

It would not work because there would be nothing to tell the OpenDataBase
command where the database was located. As it would be unusual for the
database and the Word document to be in the same folder, it is not
surprising that the document in which the Word document is located is not
considered the default location for the database.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
Z

zxcv

Yes, it helps, thanks. I just thought that when you specify only the file
name itself with no directory path information, the default location was the
same directory regardless of the situation or command. Obviously I was wrong!
 

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