Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    ultra5219 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2013
    Posts
    45

    Search Like key words

    hi guys


    i did try create search data using search Text box find. my question is, how to add search keyword function?
    For example if i type keyword: "JAVA" it will shows any keyword related "JAVA" on the table record for membertbl.
    i try to modified my code, it seems many syntax error.

    Thanks
    Attached Files Attached Files

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    no syntax error error as such - it you are saying this is what you want the code to do
    i
    f i type keyword: "JAVA" it will shows any keyword related "JAVA"
    you are not using wildcards which you require for this statement to work, and have some code which is never used

    you also don't need the tmp variable, just use '

    varwhere will never be null because you are assign it "ID like " etc

    and as you have constructed it, varwhere will never end in ' AND '

    Also helps if you learn to use indenting - makes your code easier to read and debug. try


    Code:
    Private Function BuildFilter() As String
    Dim varWhere As String
    If Nz(Me.txtSearch, "") <> "" Then
        varWhere = "WHERE [ID] like '*" & Me.txtSearch & "*' OR  [Membership_ID] Like '*" & Me.txtSearch & "*' OR [Membership_name] Like '*" & Me.txtSearch & "*' OR  [Book_ID] Like '*" & Me.txtSearch & "*' OR  [Book_Name] Like '*" & Me.txtSearch & "*' OR  [Book_location] Like '*" & Me.txtSearch & "*'"
    Else
        varWhere = ""
    End If
    BuildFilter = varWhere
    End Function

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    no syntax error error as such - it you are saying this is what you want the code to do
    i
    f i type keyword: "JAVA" it will shows any keyword related "JAVA"
    you are not using wildcards which you require for this statement to work, and have some code which is never used

    you also don't need the tmp variable, just use '

    varwhere will never be null because you are assign it "ID like " etc

    and as you have constructed it, varwhere will never end in ' AND '

    Also helps if you learn to use indenting - makes your code easier to read and debug. try


    Code:
    Private Function BuildFilter() As String
    Dim varWhere As String
    If Nz(Me.txtSearch, "") <> "" Then
        varWhere = "WHERE [ID] like '*" & Me.txtSearch & "*' OR  [Membership_ID] Like '*" & Me.txtSearch & "*' OR [Membership_name] Like '*" & Me.txtSearch & "*' OR  [Book_ID] Like '*" & Me.txtSearch & "*' OR  [Book_Name] Like '*" & Me.txtSearch & "*' OR  [Book_location] Like '*" & Me.txtSearch & "*'"
    Else
        varWhere = ""
    End If
    BuildFilter = varWhere
    End Function

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    cross posted here

    http://www.access-programmers.co.uk/...d.php?t=288447

    @ultra - please read this thread about cross posting http://www.excelguru.ca/content.php?184

  5. #5
    ultra5219 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2013
    Posts
    45
    Quote Originally Posted by Ajax View Post
    no syntax error error as such - it you are saying this is what you want the code to do
    i
    you are not using wildcards which you require for this statement to work, and have some code which is never used

    you also don't need the tmp variable, just use '

    varwhere will never be null because you are assign it "ID like " etc

    and as you have constructed it, varwhere will never end in ' AND '

    Also helps if you learn to use indenting - makes your code easier to read and debug. try


    Code:
    Private Function BuildFilter() As String
    Dim varWhere As String
    If Nz(Me.txtSearch, "") <> "" Then
        varWhere = "WHERE [ID] like '*" & Me.txtSearch & "*' OR  [Membership_ID] Like '*" & Me.txtSearch & "*' OR [Membership_name] Like '*" & Me.txtSearch & "*' OR  [Book_ID] Like '*" & Me.txtSearch & "*' OR  [Book_Name] Like '*" & Me.txtSearch & "*' OR  [Book_location] Like '*" & Me.txtSearch & "*'"
    Else
        varWhere = ""
    End If
    BuildFilter = varWhere
    End Function

    Cool.. Thanks for your advise. Your code very easy and simple and it helps me out too
    anyway, one more, what if lets say, if i type any keyword which not meet any data from the subform, can show Error Message. "Search KEyword for: "ufrrf" Not Found.

    how to modify that code in VB ya?

    Thanks again

  6. #6
    ultra5219 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2013
    Posts
    45
    Thank you..i appologies for that noted

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    possibly - but would be obvious if no records were returned anyway.

    You would have to do a recordcount of the subform once it has had the new controlsource assigned. If it was zero then generate the message

  8. #8
    ultra5219 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2013
    Posts
    45
    Quote Originally Posted by Ajax View Post
    possibly - but would be obvious if no records were returned anyway.

    You would have to do a recordcount of the subform once it has had the new controlsource assigned. If it was zero then generate the message
    I see. Well i just asking if possible to do that
    Well here is another one i ask, If i create Search Combo Box, Which are 3 field category: MemberID, Member name & IdentityCard No.
    If i type any related keyword on combo box, it will show record on form. how to do that? i did manage to do only search by memberID.
    how to add in VB code search keyword on combo box for: memberID,name & identity card no in one combo box, then it will display if keyword match found.
    if i type any keyword or wrong memberID, or member name or identity card no wrong will show error message: "search error not found." how to add this error message in VB? maybe u can check my code problem.

    Thank again
    Attached Files Attached Files

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    how to add in VB code search keyword on combo box for: memberID,name & identity card no in one combo box, then it will display if keyword match found.
    I don't understand - isn't that is what the code already does?

    if i type any keyword or wrong memberID, or member name or identity card no wrong will show error message: "search error not found." how to add this error message in VB? maybe u can check my code problem.
    Already explained - I can see you have changed your code, but cannot see how this relates.

    Suggest provide a full description in simple english of what you are trying to do

  10. #10
    ultra5219 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2013
    Posts
    45
    Quote Originally Posted by Ajax View Post
    I don't understand - isn't that is what the code already does?

    Already explained - I can see you have changed your code, but cannot see how this relates.

    Suggest provide a full description in simple english of what you are trying to do

    I mean, this one is another method. Search record on combo box. usually people search record using text box field to type correct?
    this one is combo box method. My question is, how to add multi-field search instead memberID search only.
    thats mean, i can search by MemberID or identity card no or member name keyword?


    PS: the file i attach is only search by memberID only. if i type member name or Identity card will generate error. im not sure why is that?

    Sorry bad english thanks
    Attached Files Attached Files

  11. #11
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    OK so you want a combobox to provide a value to select a specific record to display and after you have made a selection, you want to display that record? Is that correct?

  12. #12
    ultra5219 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2013
    Posts
    45
    Quote Originally Posted by Ajax View Post
    OK so you want a combobox to provide a value to select a specific record to display and after you have made a selection, you want to display that record? Is that correct?

    yep correct. Or the user can type any keyword from combo box, then click search will display the record.

  13. #13
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    confused again
    Or the user can type any keyword from combo box
    do you mean combobox or textbox?

  14. #14
    ultra5219 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2013
    Posts
    45
    Quote Originally Posted by Ajax View Post
    confused againdo you mean combobox or textbox?
    The user type in Combobox. not textbox

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    I'm guessing this is what you want

    in the combobox rowsource put something like 'SELECT ID, FirstName, LastName FROM myTable'

    in the combobox after update event put

    me.filter="[ID]=" & comboboxnamehere
    me.filteron=true

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. How To add Words
    By aamer in forum Access
    Replies: 7
    Last Post: 11-19-2015, 06:55 AM
  2. Replies: 9
    Last Post: 10-01-2013, 08:48 AM
  3. Numbers To Words
    By Derrick T. Davidson in forum Reports
    Replies: 19
    Last Post: 03-20-2013, 02:31 AM
  4. numbers to words
    By chavez_sea in forum Access
    Replies: 14
    Last Post: 01-16-2013, 07:25 PM
  5. Creating a search button for key words
    By In need in forum Access
    Replies: 10
    Last Post: 05-01-2012, 04:21 AM

Tags for this Thread

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