Results 1 to 2 of 2
  1. #1
    Eagle2012 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Posts
    3

    Auto Append data from another database

    I'm trying to find a way to append a table A (from another database, named dbA, chosen each time from different location) into an opened dbB (tables with same structure), while keeping in mind the 2 following options:


    1- both databases are located in the same folder (same path)
    2- prompt to choose dbA (where db to append is taken from).
    With appreciation to your help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Here is example code from my project:
    Code:
    Private Sub btnImport_Click()
    
    Dim strImportDataPath As String
    Dim strTable As String
    Dim intStep As Integer
    Dim strProjNum As String
    strImportDataPath = "C:\" & Me.tbxFieldFile
    'get proj_num from import file
    Dim rs As New ADODB.Recordset
    Dim cn As New ADODB.Connection
    Set cn = New ADODB.Connection
    cn.Open ("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & strImportDataPath)
    Set rs = New ADODB.Recordset
    rs.Open "SELECT proj_num FROM projects;", cn, adOpenStatic, adLockReadOnly
    If rs.RecordCount = 0 Then
        MsgBox "No records to import."
    ElseIf IsNull(DLookup("proj_num", "projects", "proj_num='" & rs!proj_num & "'")) Then
        For intStep = 1 To 4
            Select Case intStep
                'need table name to use in the INSERT command
                Case 1
                    strTable = "projects"
                Case 2
                    strTable = "co_inputs"
                Case 3
                    strTable = "OverUnder"
                Case 4
                    strTable = "rates"
            End Select
            DoCmd.SetWarnings False
            DoCmd.RunSQL "INSERT INTO " & strTable & " SELECT * FROM [" & strImportDataPath & "]." & strTable & ";"
            DoCmd.SetWarnings True
        Next
        Me.Requery
    Else
        MsgBox "Project number already in database."
    End If
    
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Data append to table
    By ali zaib in forum Access
    Replies: 4
    Last Post: 01-13-2012, 11:22 AM
  2. Replies: 1
    Last Post: 12-21-2011, 02:11 PM
  3. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  4. Database cannot append all the records
    By Paul H in forum Queries
    Replies: 9
    Last Post: 09-19-2011, 02:43 PM
  5. Append Checkbox Data
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 06-29-2010, 04:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums