Possible to define a relative path for linked table

  • Thread starter Thread starter ghadley_00
  • Start date Start date
G

ghadley_00

Hi,

I have an access database with a table linked to an external text file.
Occasionally the location of the database and the text file change (but
are always in the same directory). Is there a way to have the location
of the external text file be a relative, rather than absolute path (to
be .\textfile.txt rather than C:\dir\textfile.txt)?

Any advice that can be provided would be provided would be greatly
appreciated/

Best wishes,

George Hadley
(e-mail address removed)
 
George,

If you are doing this in code, it's a piece of cake:

CuurentProject.Path & "\textfile.txt"

HTH,
Nikos
 
I probably wasn't clear enough; at database open, the code should
re-link the text file, something like:

strFile = CurrentProject.Path & "\textfile.txt"
DoCmd.DeleteObject acTable, "Table01"
DoCmd.TransferText acLinkDelim, "TextFile Link Specification", _
"Table01", strFile, False

where I have assumed the name of the linked table to be Table01, the
file type to be delimited and the name of the link spec to be TextFile
Link Specification. Modify as required.

The Load event of a switchboard or other form which opens on database
startup is a good place to put this code. Alternatively, put it in a
self-contained function in a general module, and fire it through an
autoexec macro.

HTH,
Nikos
 
Back
Top