Results 1 to 3 of 3
  1. #1
    ShawnCartwright is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    10

    Search all for data containing....problem.

    Hi,

    I'm new to access and visual basic and have currently set up a database. I want the search button to return all the values containing the information I have entered. Such as *Karen*. Is there away to do this by putting in a value. I saw something with '%" but dont really know what Im doing with it. Sorry bit of a noob but still trying to learn.

    I've used this code below for the search. If anyone can help me Id be grateful.



    If Me.txtSupplierNumber > "" Then
    varWhere = varWhere & "[SupplierNumber] like " & SupplierNumber & Me.txtSupplierNumber & SupplierNumber & " AND "
    End If
    Attached Thumbnails Attached Thumbnails search for all.jpg  

  2. #2
    ShawnCartwright is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    10
    Was going to delete this for being a complete tool but Im sure someone will benefit from it. Add the value "*" either side of the textbox or object you wish to search for.

    If Me.txtCustomerNumber > "" Then
    varWhere = varWhere & "[CustomerNumber] like " & CustomerNumber & "*" & Me.txtCustomerNumber & "*" & CustomerNumber & " AND "
    End If

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You need to also note that

    If Me.txtCustomerNumber > "" Then

    doesn't really validate whether or not txtCustomerNumber is populated. There are a number of ways to do that, I usually use

    If Nz(Me.txtCustomerNumber, "") <> "" Then

    which checks for Nulls (which is what the majority of 'empty' Controls/Fields actually hold) and for Zero-Length Strings ("") which, under some circumstances, can display as 'empty.'

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 7
    Last Post: 08-08-2012, 03:28 PM
  2. Replies: 12
    Last Post: 03-22-2012, 02:48 AM
  3. Problem With a Search Form
    By harris90 in forum Forms
    Replies: 5
    Last Post: 01-20-2012, 03:36 PM
  4. Problem with search function
    By sk88 in forum Access
    Replies: 2
    Last Post: 12-20-2011, 01:05 PM
  5. Search Problem
    By martyloo in forum Access
    Replies: 1
    Last Post: 09-30-2011, 02:55 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