Results 1 to 3 of 3
  1. #1
    ficmessenger is offline Novice
    Windows 10 Access 2021
    Join Date
    Aug 2023
    Posts
    5

    Search code

    I have a search routine - copied from a YouTube video - that searches a given field on a form from a button:

    Private Sub SearchMembNo_Click()




    Dim S As String


    S = InputBox("Enter Membership Number. ", "", StudentMembNo)
    If S = "" Then Exit Sub


    Me.Filter = "StudentMembNo LIKE ""*" & S & "*"""
    Me.FilterOn = True


    End Sub

    The problem I have is that StudentMembNo is not a mandatory field, so if it is empty on the form record I am on it comes up with:

    Run-time error '94':
    Invalid use of Null

    How can I make the default search blank to avoid this happening?

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Please copy your code and use the code tags, don’t provide an image of the code.

    But to solve you problem, use the nz function

    filter = “nz(fieldname) like …..

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    also:


    Code:
    Dim S As String
    
    
    S = InputBox("Enter Membership Number. ", "", StudentMembNo)
    If S = "" Then Exit Sub
    
    
    Me.Filter = "[StudentMembNo] LIKE "'*" & S & "*'"
    Me.FilterOn = True

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

Similar Threads

  1. Replies: 13
    Last Post: 10-09-2021, 02:07 AM
  2. Replies: 12
    Last Post: 02-07-2019, 05:19 AM
  3. search code for vba
    By Adish in forum Programming
    Replies: 8
    Last Post: 09-27-2015, 06:57 PM
  4. Replies: 3
    Last Post: 01-04-2015, 06:09 PM
  5. Help me in my search code
    By lyndonguitar in forum Queries
    Replies: 1
    Last Post: 03-23-2013, 11:04 AM

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