Results 1 to 5 of 5
  1. #1
    Anthony88 is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    7

    Combining queries..

    Hey there,

    I need a little help trying to combine two similar queries to save time. The current SQL codes are as follows:

    UPDATE cableconductor INNER JOIN [eMax Prices] ON cableconductor.[Item No] = [eMax Prices].[Item No]
    SET cableconductor.Cablecostperfoot = [eMax Prices].[Unit Cost]*[cableconductor].[Multiplier];

    and...


    UPDATE cableconductor INNER JOIN [eMax Prices] ON cableconductor.[Neutral Item No]=[eMax Prices].[Item No]
    SET cableconductor.Cablecostperfoot = cableconductor.Cablecostperfoot+[eMax Prices].[Unit Cost]*cableconductor.[Neutral Multiplier];

    They are obviously very similar, just a couple of changes as to where the data comes from. Still new to Access, is there some sort of "reset" I can place in between the two? Thanks in advance.

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Do you wish to run both update queries concurrently?

    It is however easy to run both queries using vb, if you have them saved

    docmd.openquery "Qry_update1"
    docmd.openquery "Qry_update2"

    I don't quite see how as you are joining each differently and updating the same field.

  3. #3
    Anthony88 is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    7
    Not concurrently. I would like to run the first, then second. I wasn't sure if it was possible since I was basically re-updating the same cells. I will be using these queries quite oftern and just thought it would be easier, and faster to run one query instead of two all the time.

  4. #4
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    The easiest thing to do then assuming you have them saved as queries in access is insert the vb as described above into a command button (right click -> build event -> code builder).

    You can also disable the run action query warning using:
    Application.setoption "confirm action queries", 0


    For more info on docmd.openquery:
    http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx

    The total should look something like

    Private sub Command0_Click()
    Application.setoption "confirm action queries", 0
    docmd.openquery "qry_update1"
    'remark here because i remember i had problems running them back to back, but that may just be im trying to run on an antiquated system
    docmd.openquery "qry_update2"
    'remark here same as above
    Application.setoption "confirm action queries", 1
    end sub

  5. #5
    Kirsti is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Another quick way to do it (and maybe easier if you're not too familiar with VBA) is to create a Macro. Action1: OpenQuery (Query Name: query1) Action2: Close (Object Type: Query, Object Name: query1). Action3: OpenQuery (Query Name: query2) Action2: Close (Object Type: Query, Object Name: query2).

    Then you can just run the macro once, rather than having to run both queries.

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

Similar Threads

  1. Combining multiple queries into one
    By kagoodwin13 in forum Queries
    Replies: 1
    Last Post: 03-27-2012, 01:29 PM
  2. Combining two queries
    By Adele in forum Queries
    Replies: 1
    Last Post: 07-16-2011, 12:17 AM
  3. combining two queries
    By camell in forum Queries
    Replies: 4
    Last Post: 03-04-2011, 02:41 PM
  4. Combining queries
    By wildlifeaccess in forum Queries
    Replies: 10
    Last Post: 09-20-2010, 07:35 AM
  5. Combining Two Queries
    By csolomon in forum Queries
    Replies: 1
    Last Post: 09-03-2009, 01:33 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