473,769 Members | 5,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Make linked table have a relative path

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********@yaho o.com

May 31 '06 #1
8 28525
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:

TimeAnalysisCon trolTable
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 TimeAnalysisCon trolTable.Contr olInfo,
TimeAnalysisCon trolTable.Contr olID
FROM TimeAnalysisCon trolTable
WHERE (((TimeAnalysis ControlTable.Co ntrolID)="Repor tDirectory"));

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(En dDate), "00") & Format(Day(EndD ate), "00") & ".xls"

With Application.Fil eSearch
.NewSearch
.LookIn = ReportDir
.SearchSubFolde rs = 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.TransferS preadsheet _
TransferType:=a cExport, _
SpreadsheetType :=acSpreadsheet TypeExcel9, _
TableName:="Que ry - All Employee Ding Only", _
Filename:=Repor tFileName, _
HasFieldNames:= True, _
Range:="ExportD ata"

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

May 31 '06 #2

gh********@yaho o.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********@yaho o.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.

May 31 '06 #3
Is there any way to do this non-programmaticall y? (just alter the
settings for an existing linked table)?

Thanks,

George

Jun 1 '06 #4
Yes. It is just a question of changing the way you get the mappiong.

For instance

Letter mapping:
V:\Team folders\Team\Da tabases\

UNC mapping:
\\gsgw.CompName .com\share\Team folders\Team\Da tabases\
=============== ========

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.

Jun 1 '06 #5
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
"..\datadirecto ry\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\Code Test\datatest.m db"
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\cod etest.

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:\Pr ojects\CodeTest \datatest.mdb
OK
;DATABASE=..\Co deTest\datatest .mdb
OK
;DATABASE=..\.. \Projects\CodeT est\datatest.md b
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.
Jun 1 '06 #6
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\dire ctory1\director y2...,
the link will be recorded with that path.

Which one are you after?
Jun 1 '06 #7
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

Jun 12 '06 #8
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.md b"

set db = currentdb
for each tdf in db.tabledefs
tdf.connect = strConnect
tdf.refreshlink
next tdf

set tdf = nothing
set dbs = nothing
Jun 12 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
78646
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!
2
2307
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 *current* page request? Here's what I'm doing: I am injecting HTML directly into ASPX pages via LiteralControl. something like this...
4
8127
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 Access DB and then add a Linked Table pointing to the table on the SQL Server and then run an "Insert Into (linked table)" query to add the new rows. I am having a problem getting the syntax to add that linked table to my local Access DB. When I...
3
9824
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 the data.mda. Hence, I have an button with the following: DoCmd.RunCommand acCmdLinkedTableManager The button works on the computer with Ms Access but not those that on
2
10419
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 question but relationated, Is posible don´t put a path to the picture in the image control (in desing) ? The Database will be move frecuntly and it will give error in the form load
1
3406
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 As String '*** You have to modify the path to where db1.mdb is located
2
15635
nico5038
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 be used to relink the tables. The Linkedtable manager does however refuse to relink tables having an "Attachment" datatype field. Symptoms: Open the Linkedtable manager and select a linked table with an "Attachment" datatype field. Now try to...
2
4303
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 consistent, but the location that the backup file is on may vary. I have gone through the entire backup and restore process, and it
1
3294
prn
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 a SQL Server box that contains some of those databases and I've got the responsibility for the Access end of the changes. In most of the cases so far, it's been a matter of trotting over to the remote location and modifying the DSN (Control Panel >...
0
9589
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.