Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100

    Building a VBA Global Keyword Search Box.


    Hi, No doubt this question would've been asked a million times before, and sorry for asking it again. I'd like to build a global keyword search box from VBA, into my form relating to numerous field records. Just wondering if someone might point me to an excellent tutorial for creating this. Thanks.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    just use multiple OR's

    me.filter="Fld1='" & strSearch & "' OR Fld2='" & strSearch & "' OR......

  3. #3
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Hi Guys, have tried to give this VBA a test run but I'm clearly out of my depth for the moment. I'm attempting to copy from a video I'm watching but am missing some important steps. Just wondering if you guys might run an eye over my code and see if anything glaringly stand out. Thanks.

    Private Sub btnSearch_Click()
    Dim SQL As String
    SQL = "SELECT AssetNameFK"
    "WHERE (AssetNameFK) LIKE '*"& Me.txtKeywords &"*'"
    End Sub

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    personally I leave * out, use Like but instruct the user how to use asterisks (or other wildcards) when required. Most users know the beginning of something and using an initial * prevents the use of indexing so the query will be slow. Use the * suffix if you want.

    me.filter="Fld1 Like '" & strSearch & "*' OR Fld2 Like '" & strSearch & "*' OR...…

  5. #5
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Thanks Ajax, does the me.filter sit beneath SQL = "SELECT AssetNameFK" ?

    The VBA I'm using is in the cmdSearch Button which is meant to read a Search textbox.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  7. #7
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Thanks Orange, I'm close to getting this except for a yellow highlighted error in my code that's popping up. I'll get it right soon enough. It seems looking at different videos, people appear to be using slightly different syntax which is what's losing me. I've got an Access 2010 bible. I'll think I'll just read it tonight. The answer may jump out there. This project I'm doing is exiting, but man, it's a real labour of love. Cheers, orange.

  8. #8
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Ok, Here's what I ran, which wiped all my records. That was a neat trick.

    Private Sub btnSearch_Click()
    Dim SQL As String

    SQL = "Me.Filter = AssetNameFK where AssetNameFK LIKE '*"& Me.txtSearch &"*'"
    me.filterOn= True

    End Sub

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You do your testing in a test environment with a test database.

    How exactly did it wipe your records?
    As requested previously, can you post a copy of you database with only a few records in tables. You will get more focused responses when readers can have hands on to test/resolve issues.

    You have a lot of posts on various subjects -can you tell us more about your project?

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    all you need is


    Code:
    Private Sub btnSearch_Click()
    
        Me.Filter = "AssetNameFK LIKE '*"& Me.txtSearch &"*'"
        me.filterOn= True
    
    End Sub
    or if you are modifying your form recordsource

    Code:
    Private Sub btnSearch_Click()
    
        Me.RecordSource = "SELECT AssetNameFK FROM sometableorother WHERE AssetNameFK LIKE '*"& Me.txtSearch &"*'"
    
    End Sub

  11. #11
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    All 800+ record rows and data vanished. When I typed in a new record, the RecrodID started at 891. So, I deleted the RecordID row, created a replacement one, and took me back to a Record 1 position. I have a copy of all my records in Excel anyway to import back into Access and all my FK tables are still In tact with their data.

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Any info on the request to post a copy of the database with only a few records ineach table?

  13. #13
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Thanks Ajax, I'm extremely new to VBA conventions and logic and am madly reading the Excel Bible, VBA chapter. I can grasp the logic of flowing tasks one after the other. I'm just in the dark with what commands and properties do what, and relate to what db objects. That's just going to be an ongoing learning process. But VBA is something I want to be competent with as it's really the game-changer in mastering Access.

    I'm coming across all these great database tweaks I'm wishing to incorporate into my project but are ahead of my learning curve at the moment.

    Orange, did I see in one of your previous posts on how to bundle up a db for posting?

  14. #14
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Hi Ajax, I tested your code above but with no result.

    Me.Filter = "AssetNameFK LIKE '*"& Me.txtSearch &"*'"
    me.filterOn= True

    End Sub.

    My AssetName Textbox recordsource is linked to AssetNameFK which has two fields:
    1: unique Autonumber
    2: AssetName

    In my frmTradeEntry. AssetNameFK, I've selected to show column 2 to display the AssetName. Could this be affecting why I'm seeing no result? Screenshot below.


    Click image for larger version. 

Name:	AssetName.jpg 
Views:	12 
Size:	48.9 KB 
ID:	35186

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I don't understand what you are saying, textboxes do not have recordsources. from your description, you should be seeing something if the assetname field is populated. I'm assuming the recordsource to the form is whatever table the assetnameFK field is in.

    However I suspect what is happening you are entering something like 'IBM' or 'Apple' in txtSearch - but then trying to apply it to the assetnameFK which is presumably a number.

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

Similar Threads

  1. Keyword or fragment search
    By orange in forum Sample Databases
    Replies: 0
    Last Post: 01-23-2015, 02:47 PM
  2. keyword search
    By Mbakker71 in forum Access
    Replies: 5
    Last Post: 02-05-2014, 06:03 AM
  3. keyword search in a combo box
    By pbouk in forum Forms
    Replies: 9
    Last Post: 05-30-2013, 09:45 PM
  4. Multiple Keyword Search
    By gatsby in forum Access
    Replies: 15
    Last Post: 01-21-2013, 10:53 PM
  5. Making a keyword search
    By timmy in forum Forms
    Replies: 9
    Last Post: 03-14-2011, 02:57 AM

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