VB seach problem using Find Method

Discussion in 'Software' started by jerome8036, Mar 11, 2005.

  1. jerome8036

    jerome8036 Private E-2

    Hi,

    I'm working on an internship and I've come across a little problem. I've created a data access page and on that page I have created a button to search by Contact's Last Name. The search works; however, if you try and search by a single letter or two or three letters it will not return any matches. I was wondering if anybody could help with this problem. I'm running windows XP pro with Access 2002.


    Below is my code that I'm working with. Thank you very much for your time!

    <SCRIPT language=vbscript event=onclick for=Command1>
    <!--

    dim rs
    set rs = MSODSC.DataPages(0).Recordset.Clone
    dim s
    on error resume next

    's = InputBox("Enter Contact Last Name","Find Contact")
    'rs.find "ContactLastName= '" & s & "'"
    rs.find "ContactLastName= '" & InputBox("Enter Contact Last Name","Find Contact") & "'"
    If (err.number <> 0) Then
    Msgbox "Error: " & err.number & " " & err.description,,"Invalid Search"
    Exit sub
    End If
    If (rs.bof) or (rs.eof) Then
    Msgbox "No Name found",,"Search Done"
    Exit sub
    End If
    MSODSC.DataPages(0).Recordset.Bookmark = rs.Bookmark

    -->
    </SCRIPT>
     
  2. Kodo

    Kodo SNATCHSQUATCH

    look up the "LIKE" operator
     
  3. jerome8036

    jerome8036 Private E-2

    1. How do I do that?
    2. What does that do?

    Thanks,

    Jarred
     
  4. Kodo

    Kodo SNATCHSQUATCH

    Well, kind of backtracking here and I have to say that using DAP is the worst thing to do. You should seriously consider going to a full blown web language like ASP, ASP.NET to work with your database.

    But to answer your current question: search for "DAO LIKE" in google. LIKE is a function that matches 'like' terms using a wildcard either prefixing or suffixing the term you're looking for, i.e.

    find something like *blarg*

    will match "hopscotchblargbeep"

    find something like blarg*

    will match "blargfoo"

    the * is the wild card.
     
  5. jerome8036

    jerome8036 Private E-2

    Ok, Here's what I've got and that isn't working, any clues?

    name = InputBox("Enter Contact Last Name","Find Contact") & "*"
    rs.find like "ContactLastName= '" & name & "'"

    Your help is greatly appreciated.
     
  6. Kodo

    Kodo SNATCHSQUATCH

    You can't concatenate the * into the string.

    rs.find "ContactLastname like '"&name&"*' "

    I'm not that great with DAO syntax because I hate DAO. ADO is much more scalable.
    In any case the above statement should work, if not, then just keep in mind that the wildcard (*) cannot be part of the string. It has to be part of the find statement.
     
  7. jerome8036

    jerome8036 Private E-2

    That worked, thanks a million!
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds