Results 1 to 8 of 8
  1. #1
    Ianw is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    21

    Copy a query and give a new name

    I have Access 2010 and I have a query that I want to take a copy of, save as and call it call it something else in the same database.



    For example "query1" I want to save as and call it "query2" does anyone know the VBA code for this.
    I have searches the forum but cannot find anything on this.


    Thanks

    Ian

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Do some basic testing/experimenting.

    1. Go to the list of queries
    2. Copy a query
    3. click or point anywhere and select Paste
    4. It will give you a new query called Copy of XXXXX where XXXXX is the name of the query you copied.
    5. Change the name to whatever you want.

  3. #3
    Ianw is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    21
    Thanks for the answer orange. However, I am trying to do this programatically. Per the help you have me the other day I have managed to figure out how to change the parameters programatically in the passthrough query I have.

    I am looking to have a control button so that when I click on it it will take a copy of the query and call it something else. The macro I have will then change the parameter in the new query and then kick everything off automatically. The bit I am missing is this piece where I can programatically copy and paste the query rather than the simple manual process you have suggested.

    Thanks



    FYI, I do appreciate your help on the parameter issue.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I wasn't aware that this was a follow on post. It just seemed a little out of the blue with no related attempts/thoughts on approach.
    Anyway, I don't use macros. In vba you could copy the sql of a query, and run it without saving it under a new name.
    Or you could create a new querydef and save it. see this sample There are others search createQuerydef MsAccess

    Happy to help.

  5. #5
    Ianw is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    21
    ok. got it. I did create a new QueryDef and it works a treat.

    Code:
    Public Sub Mytest2()
    Dim qdf As QueryDef
    Dim Posit As String
    Dim dbs As Database
        Set dbs = CurrentDb
        Set qdf = dbs.QueryDefs("qryMainACCUMTest")
        DoCmd.CopyObject , "qryMainACCUMTestParam", acQuery, "qryMainACCUMTest"
    End Sub
    I'm slowly but surely figuring this out. Thanks again for your help.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  7. #7
    Ianw is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Posts
    21
    No. Access 64 bit came with the PC.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Ok. Others have access 64 bit. It's just, as you have probably read, that it offers little to nothing for Access.
    I think the 64 and 32 bit versions come on the same CD/DVD. That's what I've read.

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

Similar Threads

  1. Replies: 13
    Last Post: 12-13-2014, 08:12 PM
  2. Replies: 4
    Last Post: 07-23-2014, 04:13 PM
  3. Replies: 3
    Last Post: 03-01-2014, 10:38 AM
  4. Query to give Subtotals of field
    By dinesh_ltjd in forum Access
    Replies: 2
    Last Post: 01-12-2013, 01:18 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