Results 1 to 4 of 4
  1. #1
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63

    Open report with wildcard where conditioon

    I have a report that opens using multiple where conditions. The following vba code works great:
    acViewPreview, ,("[Source]<>' Non-Collaborative Facility' And ([CurrentAdmit]-[DischargeDate]>2)OR Isnull([Home]) And [Home]='no'")

    I would like to include an alternate where condition that includes a wildcard where the reports pulls any record with K in the source title such as:
    acViewPreview, ,("[Source] = ' "*" & k &"*" ' And ([CurrentAdmit]-[DischargeDate]>2)OR Isnull([Home]) And [Home]='no'")

    I simply cannot get the code to execute correctly. I've never tried to utilize wildcards in vba and am not sure if it is possible. Any help would be great =)

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Read up on the Like operator.

    Your syntax should be:

    [Source] Like '*k*'

    (Note single quotes because the whole WHERE criteria clause is enclosed in double quotes.)

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    First of all, don't use = operator with wildcard, always use LIKE. Second, if you are using literal character 'k' in the criteria, needs to be in quote marks - "k" - else don't concatenate.

    This shows a solution http://www.access-programmers.co.uk/...ad.php?t=94539 but I can't get anything to work either.

    Then I found this http://stackoverflow.com/questions/6...ss-but-not-vba and that worked.

    Ooops, I was testing building an SQL SELECT statement with VBA. Building WHERE CONDITION argument for DoCmd.OpenForm (or OpenReport) does work as Rod and the first link show.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63
    Thank you so much June and Rod. This worked perfectly!!!

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

Similar Threads

  1. Querying a wildcard
    By undee69 in forum Queries
    Replies: 1
    Last Post: 10-15-2012, 06:00 AM
  2. Cant see where its wrong - VBA wildcard search.
    By shabbaranks in forum Programming
    Replies: 3
    Last Post: 03-22-2012, 03:56 AM
  3. Filter with wildcard
    By gg80 in forum Programming
    Replies: 8
    Last Post: 10-07-2011, 06:29 PM
  4. If OR statement (maybe a wildcard?)
    By Lorlai in forum Queries
    Replies: 5
    Last Post: 07-27-2011, 10:21 AM
  5. replace a character with a wildcard
    By neeedhelp in forum Programming
    Replies: 2
    Last Post: 04-11-2011, 05:02 PM

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