Error 2497 (Report Name argument)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hextupleyoodot
    New Member
    • Apr 2010
    • 2

    Error 2497 (Report Name argument)

    When I try to run the sub procedure by clicking by command button "cmdPreview ," this error occurs:

    Run-time error '2497':
    The action or method require a Report Name argument.

    I've transcribed the following code straight from a book from which I'm being taught, and to the best of my knowledge, it's been copied character for character:

    Code:
    Option Compare Database
    
    Private strReport As String
    Private Sub cmdPreview_Click()
    Dim strSQL As String
    Dim strWhere As String
    If Not IsNull(txtDistributor) Then
       strWhere = strWhere & " AND DistributorName Like " & "'" & txtDistributor & "*'"
    End If
    If Not IsNull(txtContact) Then
       strWhere = strWhere & " AND ContactName Like " & "'" & txtContact & "*'"
    End If
    If Not IsNull(strWhere) Then
        strSQL = Mid$(strWhere, 6)
    End If
    
    [B]DoCmd.OpenReport strReport, acViewPreview, , strSQL[/B]
    'Set the option group, combo boxes, and check box back to null
    Clear_Controls:
        grpReports = Null
        txtDistributor = Null
        txtContact = Null
    End Sub
    Private Sub grpReports_AfterUpdate()
    Select Case grpReports
      Case 1
       strReport = "rptVisitorsByDistributor"
    End Select
    End Sub
    The part in bold is the line that apparently has the problem. The report name argument "strReport" is a string variable that was declared at the beginning of the code, and in the Private Sub at the bottom, strReport is supposed to be set to the value of the report name that is to be opened.

    I'm relatively new to VBA (and programming in general), so any help would be great!
  • hextupleyoodot
    New Member
    • Apr 2010
    • 2

    #2
    Not sure what I did, but I got it to work. Something to do with the AfterUpdate event of the Option Group "grpReports " I think, but I'm not sure... but if it works, I won't question it.

    Comment

    Working...