ACC2: How to Attach All the User Tables on a SQL ServerID: Q123714
|
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article describes how to use a SQL pass-through query to obtain a list
of all the user tables located on a SQL Server, and then attach those
tables.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information about Access Basic, please
refer to the "Building Applications" manual.
To create a SQL pass-through query to list and attach all the tables on a
SQL Server, follow these steps:
Option Explicit
Function attach_all ()
Dim DB As Database
Dim RS As Recordset
Dim QD As QueryDef
Set DB = DBEngine.Workspaces(0).Databases(0)
' Set the QueryDef variable to the pass-through query.
Set QD = DB.OpenQueryDef("sql_tables")
Set RS = DB.OpenRecordset(QD.name, DB_OPEN_SNAPSHOT)
Do Until RS.EOF
DoCmd TransferDatabase A_ATTACH, "<Sql database>", _
QD.connect, A_TABLE, RS!Name, RS!Name
RS.MoveNext
Loop
RS.Close
QD.Close
End Function
For more information about SQL pass-through queries, search for "pass- through query," and then "Creating a SQL Pass-Through Query" using the Microsoft Access Help menu.
Keywords : kbusage OdbcSqlms
Version : 2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 8, 1999