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 gh********@yahoo.com 8 28484
Here is how I solved that type of problem for our site.(This example is
doing more than you need, but gives you the idea of how it might be
handled.)..................
I have created a control file within the app defined as:
TimeAnalysisControlTable
ControlID text
ControlInfo text
I place in that table such things as Report Directory, BaseDirectory,
etc anything that is static but is subject to change on occasion. This
way no path is hard coded anywhere in the application.
For instance
ControlID ReportDirectory
ControlInfo C:\MYApp Directory\
I have the following query defined
SELECT TimeAnalysisControlTable.ControlInfo,
TimeAnalysisControlTable.ControlID
FROM TimeAnalysisControlTable
WHERE (((TimeAnalysisControlTable.ControlID)="ReportDire ctory"));
and it is called "Query - Get Report Directory"
========================================
In my vba module I have a createanalysis function: it deletes the
output report if it happens to have already been run so that it can be
replaced by a more recent version. I then copy a master that has some
special formating etc. and then export into that copy.
function CreateAnalysis()
MasterDir = DLookup("[ControlInfo]", "Query - Get Masters
Directory")
ReportDir = DLookup("[ControlInfo]", "Query - Get Report
Directory")
ReportFileName = "Time Analysis Report " & Year(EndDate) &
Format(Month(EndDate), "00") & Format(Day(EndDate), "00") & ".xls"
With Application.FileSearch
.NewSearch
.LookIn = ReportDir
.SearchSubFolders = False
.Filename = ReportFileName
If .Execute() = 1 Then
Let match = ""
VBA.FileSystem.Kill ReportDir & ReportFileName
End If
End With
VBA.FileCopy MasterDir & "Time Analysis Ding Master.xls", ReportDir
& ReportFileName
ReportFileName = ReportDir & ReportFileName
DoCmd.TransferSpreadsheet _
TransferType:=acExport, _
SpreadsheetType:=acSpreadsheetTypeExcel9, _
TableName:="Query - All Employee Ding Only", _
Filename:=ReportFileName, _
HasFieldNames:=True, _
Range:="ExportData"
function end
===========================================
That is the general gist of the function. I does other things but that
is how I use the dlookup and the control file.
I started out a long time ago having a single record file with many
fields, but whenever I had to add another field it was a bear. Then I
saw a reference to this type of structure in in one of the groups and
have converted over to using it.
Ron gh********@yahoo.com wrote: 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 gh********@yahoo.com
If you link to a file on a local area network, make sure to use a
universal naming convention (UNC) path, instead of relying on the drive
letter of a mapped network drive in Windows Explorer. A drive letter
can vary on a computer or may not always be defined, whereas a UNC path
is a reliable and consistent way for Microsoft Access to locate the
data source that contains the linked table.
Is there any way to do this non-programmatically? (just alter the
settings for an existing linked table)?
Thanks,
George
Yes. It is just a question of changing the way you get the mappiong.
For instance
Letter mapping:
V:\Team folders\Team\Databases\
UNC mapping:
\\gsgw.CompName.com\share\Team folders\Team\Databases\
=======================
Underlined part is same as V part
The front part is basically the network mapping. Your network contact
can tell what that front part should be that you would replace V :\
with. or you can somtimes see it when you open my computer for the
network drive mapping.
In fact if they tell you that you can actually use that in IE to start
looking at and you will see the same thing that you would see if you
had put in the letter format.
I think you're going to have to write a little bit of code.
I can't find a way to make the browse dialog (in Get Data | Link Tables) to
store the path as relative. I can use expressions like
"..\datadirectory\data.mdb", but when the link is created it is resolved to
an explicit path.
The only way I know that you can do this is with code along this line:
Public Function xxx()
Dim strConnect As String
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Set dbs = CurrentDb
strConnect = ";DATABASE=..\..\Projects\CodeTest\datatest.md b"
Set tdf = dbs.TableDefs("Mailing List1")
tdf.Connect = strConnect
tdf.RefreshLink
Debug.Print tdf.Connect
Set tdf = Nothing
Set dbs = Nothing
Debug.Print "OK"
End Function
Here's the setup: both codetest.mdb and datatest.mdb are in
c:\projects\codetest.
Using the code above I was able to get the connection stored using relative
notation. Here's teh debug.print output from my 3 runs, each time changing
the assignment to strConnect:
;DATABASE=C:\Projects\CodeTest\datatest.mdb
OK
;DATABASE=..\CodeTest\datatest.mdb
OK
;DATABASE=..\..\Projects\CodeTest\datatest.mdb
OK
The printed strings are right out of the Connection property of the
tabledef. So far, so good. The thing to investigate is this: To WHAT
directory does a relative string such as this refer? You have to make sure
that you know what setting is being used as the starting point so that you
know that the ".." or "." or whatever is going up FROM the right place. If
you don't know that, you don't know that going back DOWN you wind up where
you intend.
Someone more knowledgeable about Access internal settings can probably tell
you the one to check on/set.
By the way, by "relative path" I assume that you mean "starting here, go up
one level and then down to directory xxxx".
The other post I see in this thread is showing you URL, which is not a
relative notation. Using URL you are not dependent on drive mappings, so
they are a good thing and really the best way to fly most of the time. But
they are not relative. They still point to a particular path on a
particular server. Nothing relative about it.
If you want URL notation, no sweat. Just browse that way when the link
tables dialog opens. If you browse to \\myserver\directory1\directory2...,
the link will be recorded with that path.
Which one are you after?
Is there any simple way to make the database look in the same directory
that the database is in (i.e. ".") for the linked table?
Thanks,
George
In a form that opens before any other form, you can use the tabledefs
collection to loop through all your tables and set any connection string you
want:
dim db as dao.database
dim tdf as dao.tabledef
dim strConnect as string
strConnect = currentproject.path
strConnect = ";DATABASE=" & strConnect & "\mydata.mdb"
set db = currentdb
for each tdf in db.tabledefs
tdf.connect = strConnect
tdf.refreshlink
next tdf
set tdf = nothing
set dbs = nothing This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rizaan Jappie |
last post by:
is it possible to get the relative path based on a absolute path in c#?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
|
by: Jordan Richard |
last post by:
Put another way, is there any way I can tell ASP.NET to convert a path
(imbedded in a string variable, "~/images/some_image.gif") to a
root-relative path, that the client will understand, for the...
|
by: Wayne Wengert |
last post by:
I am trying to create a VB.NET Windows application to move some data from a
local Access DB table to a table in a SQL Server. The approach I am trying
is to open an OLEDB connection to the local...
|
by: sj |
last post by:
I have written an application (CW.mde) with a seperate data (Data.mda)
file. My Data tables are linked to CW.
I want my user to be able to re-link the data.mda when they change
location/path of...
|
by: Ruymán |
last post by:
Hello!,
is possible use relative path in access? for example use "photo\image1.jpg"
instead of "c:\db\photo\image1.jpg", I try it but I cann't, but in Visual
Basic if is possible.
Other...
|
by: jdorp |
last post by:
I read KP article at support.microsoft.com (Q177594) that stated that
with the following code:
Sub Command1_Click()
Dim db1 As Database
Dim db2 As Database
Dim rs As Recordset
Dim strConnect...
|
by: nico5038 |
last post by:
Access 2007 Linkedtable manager refuses to relink tables having a field with the "Attachment" datatype.
Problem:
When placing a split database in another folder, the Linked table manager should...
|
by: BD |
last post by:
Hi there.
Using 8.2 on Windows.
I have a situation where I have a db backup, which I want to deploy to
a group of developer workstations.
The target directory for the database files will be...
|
by: prn |
last post by:
Hi folks,
Here's a weird one. We have a fair number of Access applications where the front end sits on a user's desk somewhere, but the data sits on a SQL server. We're in the process of retiring...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |