Connecting Tech Pros Worldwide Help | Site Map

Refreshing and linking SQL Tables to Access front end

 
LinkBack Thread Tools Search this Thread
  #1  
Old February 15th, 2006, 09:05 PM
Typehigh
Guest
 
Posts: n/a
Default Refreshing and linking SQL Tables to Access front end

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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.