?
Solved

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

Posted on 2011-02-21
4
Medium Priority
?
569 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
MINDSUPERB earned 1000 total points
ID: 34943131
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
ID: 34943215
Unfortunately, this needs to happen automatically every night without user intervention.
Thanks!
0
 
LVL 40

Assisted Solution

by:als315
als315 earned 1000 total points
ID: 34943740
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
ID: 34944173
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 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