refresh table link

M

Mark

Hello, I am having trouble refreshing a linked table
reference in code using Access 2002. I haven't been able
to find it documented anywhere but I have been unable to
assign a new location to the Connect property.
My code is as follows:
CurrentDb("Switchboard Items").Connect = ";DATABASE="&
strdbLoc

after the following statement, examining the connect value
shows that it has not been changed. Also it appears I
cannot do something like:
set tdf=CurrentDb("Some Table Name")
examining tdf shows the object is not set.
 
G

Graham Mandeno

Hi Mark

CurrentDb provides only a temporary reference to the current database, which
lasts only for the life of that line of code. So, if you say:
Set tdf = CurrentDb("Some Table Name")
tdf.Connect = ...
by the time the second line is executed, the object referenced by tdf has
become dereferenced.

You need to store the referene in a DAO.Database object variable:

Dim db as Database
Dim tdf as TableDef
Set db = CurrentDb
Set tdf = db.("SomeTableName")
With tdf
.Connect = ";DATABASE="& strdbLoc
.SourceTableName = "SomeTableName"
.RefreshLink
End With
Set tdf = Nothing
Set db = Nothing

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
 
T

TC

Hello, I am having trouble refreshing a linked table
reference in code using Access 2002. I haven't been able
to find it documented anywhere but I have been unable to
assign a new location to the Connect property.

I use the RefreshLink method in Access 97 ...

HTH,
TC
 
M

Mark

Thanks,
-----Original Message-----
Hi Mark

CurrentDb provides only a temporary reference to the current database, which
lasts only for the life of that line of code. So, if you say:
Set tdf = CurrentDb("Some Table Name")
tdf.Connect = ...
by the time the second line is executed, the object referenced by tdf has
become dereferenced.

You need to store the referene in a DAO.Database object variable:

Dim db as Database
Dim tdf as TableDef
Set db = CurrentDb
Set tdf = db.("SomeTableName")
With tdf
.Connect = ";DATABASE="& strdbLoc
.SourceTableName = "SomeTableName"
.RefreshLink
End With
Set tdf = Nothing
Set db = Nothing

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.

Hello, I am having trouble refreshing a linked table
reference in code using Access 2002. I haven't been able
to find it documented anywhere but I have been unable to
assign a new location to the Connect property.
My code is as follows:
CurrentDb("Switchboard Items").Connect = ";DATABASE="&
strdbLoc

after the following statement, examining the connect value
shows that it has not been changed. Also it appears I
cannot do something like:
set tdf=CurrentDb("Some Table Name")
examining tdf shows the object is not set.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top