Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Provided Answers: 1

    Red face Unanswered: export all queries to another db

    Hi all,
    below is the code I use to copy all forms from one db to another.

    Function Export()
    Dim frm As AccessObject, dbs As Object
    Set dbs = Application.CurrentProject
    ' Search for open AccessObject objects in AllForms collection.
    For Each frm In dbs.AllForms

    DoCmd.TransferDatabase acExport, "Microsoft Access", "c:\test.mdb", acForm, frm.Name, frm.Name, False
    Next frm
    End Function

    How can I copy/export all queries from one db to another?

    I have tried everything i can think of but nothings working for me.
    I have even tried this code
    Private Sub Command0_Click()

    For Each QRY In CurrentDb.QueryDefs
    DoCmd.TransferDatabase acExport, "Microsoft Access", DBNAME, acQuery, QRY.Name, QRY.Name, False
    Next QRY
    End Function
    End Sub

    But i get expected end sub error.
    ANy suggestions??

  2. #2
    Join Date
    May 2005
    Nevada, USA
    Provided Answers: 6
    Well, you have both an End Function and End Sub, which would be a problem. Here's what I would do:

      Dim db            As DAO.Database
      Dim QD            As QueryDef
      Set db = CurrentDb()
      For Each QD In db.QueryDefs
        DoCmd.TransferDatabase acExport, "Microsoft Access", "c:\db1.mdb", acQuery, QD.Name, QD.Name
      Set QD = Nothing
      Set db = Nothing

  3. #3
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    Just out of curiosity, why are you doing this in code?
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts