Results 1 to 5 of 5
  1. #1
    idle is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    6

    Search using textbox - I'm sure this is simple syntax!

    CODE:


    SELECT Tbl_Main.[id#], Tbl_Main.descrip, Tbl_Main.install, Tbl_Main.category, Tbl_Main.othertxt3 FROM Tbl_Main WHERE ((([Tbl_Main].[descrip]) Or [Tbl_Main].[id#] Like "*" & ([Forms]![Tbl_Main Query]![textSearch].[Text] & "*") And [Forms]![Tbl_Main Query]![textSearch].[Text]<>""));

    I have underlined where I believe my error is occuring. I'm wanting to search Tbl_Main, but I want to compare the text box entry to BOTH "descrip" and "id#". But, when I type, it shows nothing in this form.

    Thank you!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You wouldnt search both fields....the [id#] will be exact (dont search this),

    the [descrip] field is where you put the wildcard...: [Tbl_Main].[descrip] Like "*" & [Forms]![Tbl_Main Query]![textSearch]

  3. #3
    idle is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    6
    Okay, then how could I search the ID#?

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    You can search your ID field with wildcards too, just be aware you're going to capture a bunch of stuff you may not want.

    Your WHERE statement would be

    WHERE ((([Tbl_Main].[descrip]) Like "*" & [Forms]![Tbl_Main Query]![textSearch].[Text] & "*" OR ([tbl_main].[ID#]) like "*" & [forms]![tbl_main Query]![textSearch].[Text] & "*") And [Forms]![Tbl_Main Query]![textSearch].[Text]<>""))

    What are you trying to do with the

    And [Forms]![Tbl_Main Query]![textSearch].[Text]<>""

    portion of this where clause? Return no results if there's nothing typed in? Return everything if nothing is typed in?

    If you want to return nothing (no records) if nothing is typed in you can prevent the query from running at all just by checking for a null value in the field.

    If you are trying to return all records if nothign is typed in you don't need this statement at all.

  5. #5
    idle is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    6
    Quote Originally Posted by rpeare View Post
    You can search your ID field with wildcards too, just be aware you're going to capture a bunch of stuff you may not want.

    Your WHERE statement would be

    WHERE ((([Tbl_Main].[descrip]) Like "*" & [Forms]![Tbl_Main Query]![textSearch].[Text] & "*" OR ([tbl_main].[ID#]) like "*" & [forms]![tbl_main Query]![textSearch].[Text] & "*") And [Forms]![Tbl_Main Query]![textSearch].[Text]<>""))

    What are you trying to do with the

    And [Forms]![Tbl_Main Query]![textSearch].[Text]<>""

    portion of this where clause? Return no results if there's nothing typed in? Return everything if nothing is typed in?

    If you want to return nothing (no records) if nothing is typed in you can prevent the query from running at all just by checking for a null value in the field.

    If you are trying to return all records if nothign is typed in you don't need this statement at all.
    Thank you, I will try out the new WHERE statement.

    My goal is:
    -Return NOTHING if there is nothing typed in. (I do not know how to check for a NULL value, although the logic of it does make sense)

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

Similar Threads

  1. Multiline textbox query search
    By gustavoavila in forum Access
    Replies: 1
    Last Post: 02-10-2014, 01:56 PM
  2. Entering Data into Textbox as Search Criteria
    By Moonman in forum Programming
    Replies: 1
    Last Post: 12-16-2013, 06:11 PM
  3. Replies: 4
    Last Post: 05-17-2013, 02:38 AM
  4. Search and Find Records Textbox
    By accessissue in forum Programming
    Replies: 2
    Last Post: 04-13-2012, 06:16 PM
  5. Instant Search with textbox in Form
    By MrBeardo in forum Queries
    Replies: 1
    Last Post: 03-28-2012, 02:08 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