Results 1 to 2 of 2
  1. #1
    Robeen is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596

    Exporting Data to an External Access Database.

    Hi,

    I need help with code that will allow me to take data [All Fields] from a Table in my Database and Insert them into another identically structured Table in another MS Access accdb Database.
    I would also like to filter for records older than a month [MyDateField]


    I have tried the following code I found on line. It doesn't throw an error . . . but it doesn't perform the Insert either. I'd appreciate some help on the best way to do this.

    Code:
      Dim ws As DAO.Workspace   'Current workspace (for transaction).
      Dim db As DAO.Database    'Inside the transaction.
      Dim bInTrans As Boolean   'Flag that transaction is active.
      Dim strSql As String      'Action query statements.
      Dim strMsg As String      'MsgBox message.
      'Step 1: Initialize database object inside a transaction.
      Set ws = DBEngine(0)
      ws.BeginTrans
      bInTrans = True
      Set db = ws(0)
      'Step 2: Execute the append.
      strSql = "INSERT INTO MyTable_Archive ( Field1, Field2, Field3) " & _
        "IN ""\\MyPath\MyArchiveDB.accdb"" " & _
        "SELECT Field1, Field2, Field3 " & _
        "FROM MyTable;" 
       
      db.Execute strSql, dbFailOnError
    I'd appreciate any help.

    Thanks!!

  2. #2
    Robeen is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Cancel this. Sorry.

    I got it to work using a different approach [one I use more often]:

    Code:
                    strInsertSQL = "INSERT INTO MyTable_Archive (Fld1, fld2, fld3)  "
                    strInsertSQL = strInsertSQL & " IN ""MyPath\Archive.accdb"" "
                    strInsertSQL = strInsertSQL & "SELECT Fld1, fld2, fld3 FROM MyTable;"
    
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL strInsertSQL
                    DoCmd.SetWarnings True
    Again . . . apologies.

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

Similar Threads

  1. Replies: 3
    Last Post: 01-25-2015, 11:44 PM
  2. Replies: 2
    Last Post: 09-05-2014, 11:06 AM
  3. Replies: 1
    Last Post: 05-29-2013, 03:08 PM
  4. Replies: 9
    Last Post: 10-05-2012, 06:15 AM
  5. Exporting Attachments to an external file
    By springa in forum Import/Export Data
    Replies: 3
    Last Post: 07-17-2011, 05:33 AM

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