Multiple Update Query in Access
Results 1 to 9 of 9

Thread: Multiple Update Query in Access
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jun 2016
    Posts
    125
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Multiple Update Query in Access

    Hello, I'm trying to find a way to combine multiple update queries that are updating one table into a single query and I'm unsure of how to create it...Is there a way to do this and if so can you provide an example please...Thanks for your support...

  2. #2
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,420
    Post Thanks / Like
    Mentioned
    54 Post(s)
    Tagged
    11 Thread(s)

    Default Re: Multiple Update Query in Access

    It really depends on what the queries look like, to see if they can be combined into one query with reasonable effort. Can you post the SQL code of each query?

    Note that there is nothing inhererntly wrong with having more than one update query. If the issue is the effort it takes to run them all, you could put them all in a macro, and then simply run that macro with a single click.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  3. #3
    Board Regular
    Join Date
    Jun 2016
    Posts
    125
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Multiple Update Query in Access

    That is what we are trying to get away from, so many marco's...

    1. UPDATE BSMTimeTableTemp SET BSMTimeTableTemp.ReferenceNumber = [PaymentID], BSMTimeTableTemp.PaymentID = [ReferenceNumber];


    2. UPDATE BSMTimeTableTemp SET BSMTimeTableTemp.[1099Code] = "0"
    WHERE (((BSMTimeTableTemp.DisbursementType) Like "*Loan*"));


    3. UPDATE BSMTimeTableTemp SET BSMTimeTableTemp.InstitutionName = [Institution_FurtherName]
    WHERE (((BSMTimeTableTemp.DisbursementMethod) Like "*ACH*" Or (BSMTimeTableTemp.DisbursementMethod) Like "*Wire*"));


    4. UPDATE BSMTimeTableTemp SET BSMTimeTableTemp.DistributionType = "*" & [DistributionType]
    WHERE (((Right([DisbursementType],1))="*"));

  4. #4
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    75,121
    Post Thanks / Like
    Mentioned
    60 Post(s)
    Tagged
    6 Thread(s)

    Default Re: Multiple Update Query in Access

    You couldn't run those as one query.

    Why not create a function that runs the update queries?

    You would only need to pass it the database connection and the appropriate SQL string.
    If posting code please use code tags.

  5. #5
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,420
    Post Thanks / Like
    Mentioned
    54 Post(s)
    Tagged
    11 Thread(s)

    Default Re: Multiple Update Query in Access

    That is what we are trying to get away from, so many marco's...
    Why not combine them into one Macro?
    You can perform multiple steps in a Macro.
    Or convert it to VBA code and run all those commands with one procedure (or function, like Norie recommended).
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  6. #6
    Board Regular
    Join Date
    Jul 2010
    Posts
    432
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Multiple Update Query in Access

    I agree with the others here that it would be better to run the 4 queries in sequence, however, I think you probably could combine them in one query albeit a somewhat inefficient query:

    Code:
    UPDATE BSMTimeTableTemp SET PaymentID = [ReferenceNumber], [1099Code] = IIf([DisbursementType]  Like "*Loan*","0",[1099Code]), InstitutionName = IIf([DisbursementMethod] Like "*ACH*" Or [DisbursementMethod] Like "*Wire*",[Institution_FurtherName],[InstitutionName]), DistributionType = IIf(Right([DisbursementType],1)="*","*" & [DistributionType],[DistributionType]);
    Last edited by stumac; May 9th, 2019 at 08:50 AM.

  7. #7
    Board Regular
    Join Date
    Jun 2016
    Posts
    125
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Multiple Update Query in Access

    I'm new ti this so how would I do this, do you have any samples for me to follow....

  8. #8
    Board Regular
    Join Date
    Jul 2010
    Posts
    432
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Multiple Update Query in Access

    Not really sure about the easiest way with a macro - I think just use the open query command 4 times and point to your query (might want to set warnings off & back on to stop the prompts).

    code wise:

    Code:
    With CurrentDb
    .Execute "UPDATE BSMTimeTableTemp SET BSMTimeTableTemp.PaymentID = [ReferenceNumber]", dbFailOnError
    .Execute "UPDATE BSMTimeTableTemp SET [1099Code] = '0' WHERE DisbursementType Like ' * Loan * ' ", dbFailOnError
    .Execute "UPDATE BSMTimeTableTemp SET InstitutionName = [Institution_FurtherName] WHERE DisbursementMethod Like '*ACH*' Or DisbursementMethod Like '*Wire*'", dbFailOnError
    .Execute "UPDATE BSMTimeTableTemp SET DistributionType = ' * ' & [DistributionType] WHERE Right([DisbursementType],1)='*'", dbFailOnError
    End With
    
    
    MsgBox "Complete"
    Either add this to a new sub routine within a module or assign it to a button on a form (this would be normal practice). Create a new command button, go to properties for it and on the event tab select the 3 dots beside on click. Select code builder and then paste the code above between the sub & end sub lines.
    Last edited by stumac; May 10th, 2019 at 05:25 AM.

  9. #9
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,420
    Post Thanks / Like
    Mentioned
    54 Post(s)
    Tagged
    11 Thread(s)

    Default Re: Multiple Update Query in Access

    Not really sure about the easiest way with a macro - I think just use the open query command 4 times and point to your query
    Exactly. It is as simple as starting a new Macro, and using the OpenQuery command four times, once opening each query. Then to run all of them in sequence, all you need to do is to run that Macro.

    And you can easily convert that Macro to VBA code, if you want, by selecting it and then clicking on the "Convert Macros to Visual Basic" button in the Macro menu. That is helpful if you want to convert that macro to a procedure or function, or want to make it more dynamic.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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