Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wildcard Report Criteria (A2K)

    I have a generic report which I can use for numerous combinations of data via a series of queries. I had no problem in setting up the criteria in the query using the following code:

    QueryName: qry 01 CN
    Field Name in Query: F01_RA_Service
    Two criteria conditions:

    Like "*NER*"
    Or
    Not Like "*NER*"

    When I tried to do the following in going to print, Access got all upset


    Private Sub prvPS01_Click()
    Dim strWhere As String
    If Not Like "*NER*" ([F01_RA_Service]) then
    End If
    On Error GoTo Err_Click
    DoCmd.OpenReport ReportName:="rpt Name", View:=acViewPreview, WhereCondition:=strWhere
    DoCmd.RunCommand acCmdZoom100
    Exit Sub
    Err_Click:
    If Err <> 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    Private Sub prvPS01_Click()
    Dim strWhere As String
    If Like "*NER*" ([F01_RA_Service]) then
    End If
    On Error GoTo Err_Click
    DoCmd.OpenReport ReportName:="rpt Name", View:=acViewPreview, WhereCondition:=strWhere
    DoCmd.RunCommand acCmdZoom100
    Exit Sub
    Err_Click:
    If Err <> 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    I've checked thru the forum and many "similar", but not with a wildcard setup.

    Thanks in advance for any help on this
    Cheers,
    Andy

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Wildcard Report Criteria (A2K)

    Code such as

    If Not Like "*NER*" ([F01_RA_Service]) then
    End If

    is incorrect and if it were correct it wouldn't do anything because there is nothing between the If ... Then and End If lines. Try the following:
    <code>
    strWhere = "F01_RA_Service Not Like 'NER*'"
    </code>
    or
    <code>
    strWhere = "F01_RA_Service Like 'NER*'"
    </code>
    Note the use of single and double quotes.

  4. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard Report Criteria (A2K)

    Hans,

    Apologies for the delay in responding.

    Of course your code worked. Seemingly simple when you lay it.
    Cheers,
    Andy

Posting Permissions

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