Refresh Linked Tables in Access2000

H

HSalim

Hi All,
I have an A2K database and have linked a few tables - currently using a DSN.
I know how to refresh the tables if needed using DAO (thanks to Dev Ashish
and MS KBID 159691)

I am trying not to use ADO but can't find a way to do so.
Is this possible?

Regards
Habib
 
L

Larry Linson

The question I'd ask is: if you are working with Jet database tables, as it
seems you are, why would you want to use ADO? DAO is preferable for Jet: it
is the native language of Jet, is faster than ADO for Jet, and is more
complete than the combination of ADO and ADOX.

Larry Linson
Microsoft Access MVP
 
H

HSalim

Hi Larry,
I am actually connecting to a SQL server.
Also, I wanted to see if I could do it in ADO, partly as an academic
exercise.

Regards
Habib
 
L

Larry Linson

ADO is particularly designed for connecting to server databases and learning
ADO, even with Jet databases, is also a perfectly good reason.

I've seen some anecdotal evidence, however, indicating that ADO is not
necessarily a better performer than DAO/Jet/ODBC. Clearly, there are people
who like it very much and use it almost exclusively, even for Jet databases.

But, because DAO/Jet/ODBC has always nicely filled my needs for
client-server, I don't have the ADO background to answer specific, detailed
ADO questions.

Larry Linson
Microsoft Access MVP
 
H

HSalim

Hi User,
Thanks for the reply.
Actually, I saw that article once before and skimmed past it.

I experimented with the code and tried using it to suit my needs.
Everything goes fine till i get to the end - when i try to set the property
for the DataSource and the Provider String
- instead of setting the property, it opens the ODBC Administrator window.
(both times)
I want it to be done programatically with no need for user interaction.

So for now, I'll ahve to go the DAO way of doing it.

One more quesstion. I get an error when I try to use
CurrentProject.BaseConnectionString.

The error is:
The database has been placed in a state by user 'Admin' on machine
'MyMachine'
that prevents it from being opened or locked.

Any ideas?

Regards
Habib
 
U

User

If I recall correctly, I also ran into some problems trying to refresh links
as opposed to recreating them from scratch. The following code is edited
and redacted (hopefully without introducing bugs). Orginal code did other
things as well. This is for linking MS SQL tables. ADO/ADOX 2.6 or
higher is recommended.

I don't understand the question about CurrentProject.BaseConnectionString.

=========

Private Const ODBC_ConnectionString As String = _
"ODBC;Driver={SQL
Server};Trusted_Connection=Yes;Server=ServerName;Database=DBName"

Public Sub ReCreateLinks()
Dim cat As ADOX.Catalog, ncat As ADOX.Catalog
Dim tbl As ADOX.Table, ntbl As ADOX.Table
Dim local_name() As String, remote_name() As String
Dim ntabs As Long, i As Long
Dim stemp As String

' Note, must have ODBC; in string, or else you will get
' the error: "80004005 - Could not find installable ISAM."
stemp = ODBC_ConnectionString

' Open the catalog for current database.
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection

ntabs = 0
ReDim local_name(100)
ReDim remote_name(100)

' Get list of SQL PASS-THROUGH tables - cannot modify catalog at same
time.
' SQL: PASS-THROUGH ; Paradox: LINK ; Access: TABLE, VIEW
For Each tbl In cat.Tables
Debug.Print tbl.Name, tbl.Type
If tbl.Type = "PASS-THROUGH" Then
If ntabs > UBound(local_name) Then
ReDim Preserve local_name(UBound(local_name) + 10)
ReDim Preserve remote_name(UBound(local_name) + 10)
End If

local_name(ntabs) = tbl.Name
remote_name(ntabs) = tbl.Properties("Jet OLEDB:Remote Table
Name")
ntabs = ntabs + 1
End If
Next

' ReCreate tables
i = 0
Do While i < ntabs
cat.Tables.Delete local_name(i)
Call LinkSQLTable(local_name(i), remote_name(i), stemp)
i = i + 1
Loop

Debug.Print ntabs & " tables linked."
cat.Tables.Refresh
End Sub

=========

Public Function LinkSQLTable(local_name As String, remote_name As String,
cns As String)
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table

' Open the catalog using the current Access database.
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection

' Create the new table.
Set tbl = New ADOX.Table
tbl.Name = local_name
Set tbl.ParentCatalog = cat

' Set the properties to create the link.
' Note: For Access link the Provider must be Jet OLEDB - do not specify.
tbl.Properties("Jet OLEDB:Create Link") = True
tbl.Properties("Jet OLEDB:Link Provider String") = cns
' tbl.Properties("Jet OLEDB:Link Datasource") = ""
tbl.Properties("Jet OLEDB:Remote Table Name") = remote_name

' Append the table to the tables collection of the catalog.
cat.Tables.Append tbl
Set cat = Nothing
End Function

=========
 
T

Tony Toews

HSalim said:
I have an A2K database and have linked a few tables - currently using a DSN.

I much prefer DSN-Less connections as it is one less thing for someone
to have to configure and one less thing for the users to screw up.

Using DSN-Less Connections
http://members.rogers.com/douglas.j.steele/DSNLessLinks.html

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 

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