Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    144

    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
    DoEvents
    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
    DoEvents
    Next QRY
    End Function
    End Sub

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

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

    Code:
      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
      Next
    
      Set QD = Nothing
      Set db = Nothing
    Paul

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

    The problem with making anything foolproof...is 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
  •