Solved

Need to copy linked tables from SQL Server to local copy.

Posted on 2011-02-21
4
509 Views
Last Modified: 2012-05-11
I have links to SQL Server 2005 in my Access 2008 database.  But my reports are running really slow due to network issues.  So I need to make a local copy of all the tables I've linked, every night during my update process.  So, I've tried to re-create the code someone else posted on this site.  But, I'm getting the error 3170: Could not find installable ISAM.  And I don't know what else I might be getting wrong.  I'm kind of new to this stuff.  Could anyone help me?  Here's the code I've got so far.   I've added the word "Link_" to the beginning of each linked table so that the local copy can have the original name the rest of the code in the db is written for.  Thank you!

Public Sub test_Click()

    Dim dbs As Database
    Dim tdf As TableDef
    Dim strLinkedTableName As String
    Dim strSourceTableName As String
   
    On Error GoTo ErrHandler
   
    Set dbs = CurrentDb()
    For Each tdf In dbs.TableDefs
        If (tdf.Attributes And dbAttachedODBC) Then
'store the linked table name
            strLinkedTableName = tdf.name
'store the source table name
            strSourceTableName = Mid(strLinkedTableName, 6)
'import the source table
            DoCmd.TransferDatabase TransferType:=acImport, _
                                   DatabaseType:="ODBC Database", _
                                   Databasename:="DSN=ejacketprod_db;DATABASE=eJacketprod_db;UID=abc;PWD=xyz;", _
                                   ObjectType:=acTable, _
                                   Source:=strSourceTableName, _
                                   Destination:=strSourceTableName, _
                                   StructureOnly:=False, _
                                   Storelogin:=True
            On Error GoTo ErrHandler
        End If
    Next
     
ExitHandler:
    On Error Resume Next
    Set tdf = Nothing
    Set dbs = Nothing
    Exit Sub
ErrHandler:
    Select Case Err.Number
        Case Else
            MsgBox Err.Number & ": " & Err.Description
    End Select
End Sub
 
0
Comment
Question by:sarahellis
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
MINDSUPERB earned 250 total points
Comment Utility
If you can view your link tables in the navigation pane, you can select all the link tables then copy and paste it back. Select Structure and Data and click OK.

This would be the quick and easiest way to do to go away with code errors.

Sincerely,
Ed
0
 

Author Comment

by:sarahellis
Comment Utility
Unfortunately, this needs to happen automatically every night without user intervention.
Thanks!
0
 
LVL 39

Assisted Solution

by:als315
als315 earned 250 total points
Comment Utility
As addition to Ed's advice (source tables are linked):
Dim SQL as String
For Each tdf In dbs.TableDefs
        If (tdf.Attributes And dbAttachedODBC) Then
'store the linked table name
            strLinkedTableName = tdf.name
'store the source table name
            strSourceTableName = Mid(strLinkedTableName, 6)
'import the source table
           SQL = "SELECT " & strSourceTableName & ".* INTO " & strLinkedTableName &" FROM " & strSourceTableName &";"
           docmd.openquery SQL
            On Error GoTo ErrHandler
        End If
    Next
0
 

Author Comment

by:sarahellis
Comment Utility
I found what I was looking for on another site.  Thank you for your suggestion.  Your way would have worked too, so I will award points.  But I really wanted to use the transferdatabase method.  In case anyone is interested, the code is:

Public Sub test_Click()

    Dim dbs As Database
    Dim tdf As TableDef
    Dim strLinkedTableName As String
    Dim strSourceTableName As String
   
    On Error GoTo ErrHandler
   
    Set dbs = CurrentDb()
    For Each tdf In dbs.TableDefs
           
'store the linked table name
            strLinkedTableName = tdf.name
'store the source table name
            strSourceTableName = "dbo." & Mid(strLinkedTableName, 10)
'delete old copied table
            If TExists(Mid(strLinkedTableName, 6)) = True Then
                DoCmd.DeleteObject acTable, Mid(strLinkedTableName, 6)
            End If
'import the source table
            DoCmd.TransferDatabase acImport, "ODBC Database", _
                "ODBC;Driver={SQL Server}; Server=ProdServer;DATABASE=prod_db;UID=abc;PWD=xyz", _
                acTable, strSourceTableName, strSourceTableName, StructureOnly:=False

            On Error GoTo ErrHandler
        End If
NextRec:
    Next
     
ExitHandler:
    On Error Resume Next
    Set tdf = Nothing
    Set dbs = Nothing
    Exit Sub
ErrHandler:
    MsgBox Err.Description
    Resume ExitHandler
End Sub
 

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now