Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 21st, 2006, 01:35 AM
Saintor
Guest
 
Posts: n/a
Default A simple example of reattaching one table by VBA

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


  #2  
Old January 21st, 2006, 04:45 AM
Allen Browne
Guest
 
Posts: n/a
Default Re: A simple example of reattaching one table by VBA

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" <saintor1@REMOVETHIShotmail.com> wrote in message
news:hCfAf.32427$lf2.292051@wagner.videotron.net.. .[color=blue]
> 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[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles