Connecting Tech Pros Worldwide Help | Site Map

Refreshing and linking SQL Tables to Access front end

  #1  
Old February 15th, 2006, 10:05 PM
Typehigh
Guest
 
Posts: n/a
I have a routine that replicates a table with an existing table (used
as a template) in SQL Server. The desired new table name is passed to
the routine along with the template table name.
The code successfully creates the new table, but it doesn't appear
until I manually refresh the Tables list in SQL Server.

I need the vba code that will refresh the SQL Tables and then link the
newly created table back to the MS-Access front end. I have included
the routine so you can see my elegant code <grin>.

Thanks in advance for any help.


Public Sub DuplicateSQLTable(strNewTable As String, strTemplate As
String)
Dim cn As New ADODB.Connection
Dim rst As ADODB.Recordset
Dim blnExists As Boolean

'SQL_SERVER_NAME = The name of the SQL Server
'SQL_DATABASE_NAME = The name of the database

' Opening connection using Windows Authentication to connect to the SQL
Server
cn.Open "Provider=SQLOLEDB.1;Data Source=" & SQL_SERVER_NAME & "; & _
Initial Catalog=" & SQL_DATABASE_NAME & ";Integrated Security='SSPI'"


'Check to see if table already exists
Set rst = cn.OpenSchema(adSchemaTables)
blnExists = False
Do Until rst.EOF
If rst!TABLE_NAME = strNewTable Then
blnExists = True
Exit Do
End If
rst.MoveNext
Loop
rst.Close
set rst = Nothing

If blnExists Then 'Drop the existing table
cn.Execute "DROP TABLE " & strNewTable
End If

'Create the table
cn.Execute "Select * INTO " & strNewTable & " FROM " & strTemplate

'Now link the table back to Access
'This is where I need the code

cn.Close
Set cn = Nothing
End Sub

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to programmatically refresh linked tables bubbles answers 24 May 5th, 2007 12:35 AM
ADP vs. MDB: Speed Neil answers 60 November 13th, 2005 10:11 AM
Refreshing linked tables - repeat for EVERY table Lewis Veale answers 6 November 13th, 2005 09:00 AM