By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 1,756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

A simple example of reattaching one table by VBA

P: n/a
Can somebody provide the minimal code (DAO) to link one Access table from
an external file (A2K)?

I have seen the examples in MVPS/MS and the code seems to want to to
everything. just can't get the essential.

Is there any difference between A97 and A2K?

TIA
Jan 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The code is the same for A97 and later versions.

The basic idea is to loop through the TableDefs collection.
Skip these tables:
- no Connect string (so they are local tables),
- temp (name starting with "~"),
- system tables (names starting with MSys.)
For the others, set the Connect property, and RefreshLink.

Basic example:
Dim tdf As DAO.TableDef
For Each tdf In dbEngine(0)(0).TableDefs
If ((tdf.Attributes And dbSystemObject) = 0) And (tdf.Connect <>
vbNullString) And Not (tdf.Name Like "~*") Then
tdf.Connect = ";DATABASE=C:\MyFolder\MyFile.mdb"
tdf.RefreshLink
End If
Next

The lengthy code at the mvps site tests first to see if a reconnect is
necessary (by trying to OpenRecordset with error handling.) If it is, it
pops up the File Open dialog so the user can choose the file to connect to.
That involves an API call, and that's what most of the lengthy code is for.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Saintor" <sa******@REMOVETHIShotmail.com> wrote in message
news:hC********************@wagner.videotron.net.. .
Can somebody provide the minimal code (DAO) to link one Access table from
an external file (A2K)?

I have seen the examples in MVPS/MS and the code seems to want to to
everything. just can't get the essential.

Is there any difference between A97 and A2K?

TIA

Jan 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.