Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2003
    Posts
    14

    Unanswered: SQL Query (wildcards)

    Just changing the location of this post cause I didnt have any luck and may have put it in the wrong place


    In access when I start my query I want to search for a record that I specify and preferably part of a recod.

    At the moment my Query looks something like this..

    SELECT Contacts.NameFirst FROM Contacts WHERE ((Contacts.NameFirst Like "*" & [Enter First Name]));

    The problem is this will bring up the data im looking for as long as i dont inlude the first letter. for example if OI wanted to find "station" then "tion" would find my record but "stat" would not.

    It Does however find my record if I type the whole name e.g. "station"

    Any help with this would be appreciated

    Cheers

    Darin

  2. #2
    Join Date
    Jan 2003
    Location
    Rockville, MD
    Posts
    179

    Re: SQL Query (wildcards)

    Hi Darin,

    Try putting an asterisk after the criteria too.

    SELECT Contacts.NameFirst FROM Contacts WHERE ((Contacts.NameFirst Like "*" & [Enter First Name] & "*"));

    Good Luck,
    JT

  3. #3
    Join Date
    Aug 2003
    Posts
    14
    Thankyou very much for the help JT, thats perfect...

    Darin

  4. #4
    Join Date
    Aug 2003
    Posts
    14
    Something else I was wondering if it was possible to do?

    To extend on the above, if I wanted to do a query like the above but give the operator the option of searching a different field such as a drop down list of first name last name etc... but still using an sql query.

    Does anyone have any idea how to do this? I may not have explained that very well.

    Darin

  5. #5
    Join Date
    Jan 2003
    Location
    Rockville, MD
    Posts
    179
    Try this Darin,

    SELECT Contacts.NameFirst FROM Contacts WHERE ((Contacts.NameFirst Like "*" & [Forms]![FormName]![ComboBoxName] & "*"));

    Where "FormName" is the name of your form, and "ComboBoxName" is the name of the drop-down list on your form.

    If it's an exact match, you might want to remove the asterisks.

  6. #6
    Join Date
    Aug 2003
    Posts
    14
    Thanks I'll have to play around with that a bit.

  7. #7
    Join Date
    Aug 2003
    Posts
    14
    Cheers again JT

    Ok I got that Sussed and used a text box as the search reference for the first name like this.

    WHERE ((Contacts.NameFirst Like "*" & Forms!Search!txtfirst & "*"));

    Is there any way that I can add a last name text box and say company in that SQL so that it matches 3 fields at once?

    I hope that makes sense...

    Darin

  8. #8
    Join Date
    Aug 2003
    Posts
    14

    Thanks ;)

    Forget that last post I worked it out, thatnks for all your help!!

  9. #9
    Join Date
    Jan 2003
    Location
    Rockville, MD
    Posts
    179
    Sorry Darin,

    I didn't see that last question.


    Why not post the solution for curious lurkers?

Posting Permissions

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