Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2011
    Posts
    2

    Unanswered: Passing a variable from a form to a report

    Hello,
    This is my first time posting, so I hope I'm doing this right.
    I'm using VBA in Access 2003 and I have a form, a query and a report. The form is just a combo box with a list of names. The user picks one name which I want the report to use basically as a parameter. So if the name is John Smith, the report will give back dates of speeches and locations of speeches for John Smith. The code looks like this: (It executes when the user presses the OK button on the form)

    Private Sub cmdOK_Click()
    Dim strWhere As String
    If Not IsNull(Me.cmbAttyName) Then
    strWhere = Me.cmbAttyName.Value

    DoCmd.OpenReport "RptAttorneyActivity", acViewPreview, , ("Attorney") = "'" & strWhere & "'"

    __________
    I put in a message box to see if the form was picking up the value of the attorney name and it is. But when the report runs it is blank. I've checked the spelling, I've checked to make sure the selected attorney actually has records. I've also checked to be sure the field name is correct. The report doesn't error out, it just doesn't do anything. I'm relatively new at this, so please excuse my blundered code. Thanks.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Try this line:

    DoCmd.OpenReport "RptAttorneyActivity", acViewPreview, , "Attorney = '" & strWhere & "'"
    Paul

  3. #3
    Join Date
    Sep 2011
    Posts
    2

    Thank you!

    That worked perfectly!

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Happy to help, and welcome to the site by the way!
    Paul

Posting Permissions

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