jearlcalkins
Programmer
Question ... Can ADO, under ACCESS VBA create a TABLE (linked) against a SQL SERVER DB?
I am unable to create a new ODBC link table under ACCESS 2000, using ADO objects connecting to a SQL SERVER 7 database. The application will not let me set properties on a new table. The source of the code below is a Microsoft KB "HOWTO: Link and Refresh Linked Jet Tables Using ADOX(Q230588)". When the application attempts to set properties for the table link, the following error occurs: Run-time error '3265': Item cannot be found in the collection corresponding to the requested name or ordinal.
..........................
Option Compare Database
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim cnn As ADODB.Connection
Public Function Add_link_table()
result = CreateLinkedTable("dbo_Product"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
End Sub
Public Function CreateLinkedTable(strLink As String)
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
Set cnn = New ADODB.Connection
cnn.Open "PROVIDER=MSDASQL;DSN=DataSql;DATABASE=RepSql;User ID=sa;Password=;Trusted_Connection=yes;"
cat.ActiveConnection = cnn
tbl.Name = strLink ' Create the new table
Set tbl.ParentCatalog = cat
' Set the properties to create the link ... ERROR occurs next line
tbl.Properties("Jet OLEDB:Link Datasource"
= strTransport
tbl.Properties("Jet OLEDB:Remote Table Name"
= strLink
tbl.Properties("Jet OLEDB:Create Link"
= True
' Append the table to the Tables collection
cat.Tables.Append tbl
Set cat = Nothing
cnn.Close
End Function
I am unable to create a new ODBC link table under ACCESS 2000, using ADO objects connecting to a SQL SERVER 7 database. The application will not let me set properties on a new table. The source of the code below is a Microsoft KB "HOWTO: Link and Refresh Linked Jet Tables Using ADOX(Q230588)". When the application attempts to set properties for the table link, the following error occurs: Run-time error '3265': Item cannot be found in the collection corresponding to the requested name or ordinal.
..........................
Option Compare Database
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim cnn As ADODB.Connection
Public Function Add_link_table()
result = CreateLinkedTable("dbo_Product"
End Sub
Public Function CreateLinkedTable(strLink As String)
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
Set cnn = New ADODB.Connection
cnn.Open "PROVIDER=MSDASQL;DSN=DataSql;DATABASE=RepSql;User ID=sa;Password=;Trusted_Connection=yes;"
cat.ActiveConnection = cnn
tbl.Name = strLink ' Create the new table
Set tbl.ParentCatalog = cat
' Set the properties to create the link ... ERROR occurs next line
tbl.Properties("Jet OLEDB:Link Datasource"
tbl.Properties("Jet OLEDB:Remote Table Name"
tbl.Properties("Jet OLEDB:Create Link"
' Append the table to the Tables collection
cat.Tables.Append tbl
Set cat = Nothing
cnn.Close
End Function