Search Multiple Columns

KevinS

New member
Local time
Yesterday, 22:39
Joined
Nov 17, 2011
Messages
5
So I have read all the posts in regards to using a search box for searching records and can't get anything to work. It would seem to be a simple fix, but here's what I'm trying to accomplish:

I created a database in Access 2007 using the Contact Management Database template. There is a search function in the form that allows to type in a name or city or whatever to retrieve a particular contact record. The problem is that it only has the capability to search one column at a time. For example, I can't search for a name AND city. Is there a way I can modify this search box to return records so that when I enter words that are in different columns, it retrieves the contact(s) that meet both the specified criteria?
 
The search button should be something like:

Code:
Dim strFilter As String
 
strFilter = "[Name] Like " & Chr(34) & "*" & Me.TextBoxNameHere & "*" & Chr(34) & _
              " OR [City] Like " & Chr(34) & "*" & Me.TextBoxNameHere & "*" & Chr(34)
 
Me.Filter = strFilter
Me.FilterOn = True

(and by the way, it isn't good to have a field name or object name with Access Reserved Words - NAME is one of them)
 
The sample here my also be of interest to you.
 
Bob,

Thanks for helping me out, I appreciate it. I am relatively new to Access and creating databases, so I'm still running into obstacles even when I think I have it figured out. Here's what I did and maybe you can tell me where I went wrong:
  • Created a Text Box
  • Creater a Button next to it (Record Navigation - Find Record)
  • Deleted the Embedded Macro, opend VBA and pasted the code you provided, changing the appropriate words (In this case, First Name, City and Text Box Name)
  • I saved it and when I tried to put a name in and search, nothing happened
Did I miss a step or am I doing something totally wrong? Thanks again for your help, it is much appreciated!

Kevin
 
John,

Thanks for your help, I read your entry and tried it out before posting this message. I followed the steps exactly and when I type something in, nothing happened. Any recommendations?
 
The fact that nothing happens would suggest that something is not quiet right in the way you have implemented the solution.

My suggestion is that you download the sample, and play around with that and become familiar with it's inner and outer workings prior to trying to implement it in a new DB.
 
Post the exact code you now have that doesn't appear to work. Also, make sure the form's DATA ENTRY property is NOT set to YES.
 

Users who are viewing this thread

Back
Top Bottom