How do I pass variable value to the report that uses query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jakubmakowski
    New Member
    • Sep 2015
    • 1

    How do I pass variable value to the report that uses query

    Hello,
    I have a problem with opening the report using a variable from the access form.
    Suppose I have a form with customer data - one of the fields is called "ClientID" and in the same databese I have a report that uses a query that one of the parameters is "Like [Enter ClientID:]". When report starts the user is prompted: "Enter ClientID:" If user puts from keyboard "ClientID" the command shows a report for the entered value.
    I would like to ask if there is a way for the report/query to take the "ClientID" from the form with customer data.
    Thanks in advance for help.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    Replace the [Enter ClientID:] in the query with Forms!Form_Name _Here!ClientID

    Comment

    • jforbes
      Recognized Expert Top Contributor
      • Aug 2014
      • 1107

      #3
      I would remove the Query Parameter so that if the Report is opened, it will show reports for every Client in the Database. Then when calling the OpenForm in VBA, supply the Where Condition to limit the Report to only the Client that you want.

      Here is a real world example:
      Code:
      Private Sub cmdQuotePreview_Click()
          Dim sQuoteNumber As String    
          sQuoteNumber = Nz(Me!QuoteNumber, "")   
          If Len(sQuoteNumber) > 0 Then DoCmd.OpenReport "rptQuote", acViewPreview, , "QuoteNumber='" & Me!QuoteNumber & "'"
      End Sub

      Comment

      Working...