Results 1 to 4 of 4
  1. #1
    Hursan is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2021
    Posts
    23

    Running two queries with same parameters at once

    I have a button that runs run two queries at the same time:



    1st - CollectionQueryReport - generates and prints a report
    2nd - NicelabeQuery - generates a table that is exported to a network drive


    Both queries use the same parameter, when the user clicks on the button access asks for the parameter 6 times, and this runs the first query. but then access asks the user for the parameter again to run the second query.
    is there a way to prevent access from asking for the parameter twice?


    Is there a way to prevent error MS access error 2510 window if the user clicks cancel on the Enter Parament Value window?

    Code:
    Private Sub CollectionReport_Click()
    
    
    LResponse = MsgBox("Are You Ready To Print Collection and Labels Reports?", vbYesNo, "Run Report?")
    
    
    If LResponse = vbYes Then
        DoCmd.OpenReport "CollectionQueryReport", acViewNormal
        DoCmd.OutputTo acOutputQuery, "NiceLabelQuery", acFormatXLSX, "\\ServerName\Shared\Folder\Database\Tablet 1\NiceLabels.xlsx"
    
    
    Else
           Cancel = True
    End If
    End Sub

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,387
    is there a way to prevent access from asking for the parameter twice?
    yes, use a form for the user to enter the parameters and have your queries reference the form

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,702
    There is no Cancel for a button click event. If it doesn't raise any error it's because that line has never been executed and you're not using Option Explicit (or you are but have not compiled the code project). Then the Else part isn't required because if the response is no, nothing will happen.

    If you don't use a form as suggested, you'd have to code everything so that you could run sql statements for the report query as well as the label query and handle situations where input is cancelled not provided.

    For years I've looked up error messages related to the thousands of numbers that exist for the numbers people post, but not today. You need to provide that message. Besides, if you write a code solution, you should be able to avoid it anyway. I'm not saying code is a better solution than a form because it's usually not.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Hursan is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2021
    Posts
    23
    Thank you, I did not think about the form, this fixed the problem.

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

Similar Threads

  1. Replies: 8
    Last Post: 01-26-2022, 10:01 AM
  2. Replies: 1
    Last Post: 12-19-2016, 01:46 PM
  3. Replies: 11
    Last Post: 11-13-2015, 05:11 PM
  4. Running queries, VIA VB, but not running in Order
    By mike02 in forum Programming
    Replies: 6
    Last Post: 06-01-2013, 07:07 AM
  5. Replies: 1
    Last Post: 03-05-2011, 03:05 PM

Tags for this Thread

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