Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find / Search for record in employee form 1

Status
Not open for further replies.

gogirl

MIS
Jun 5, 2002
46
US
Hello,

On my employee info. form I have created a find button but I don't know the best way to make it work. I want to search 2 fields (first name and last name) and have the form display the employee if the input matches. The input comes from an InputBox which displays a message asking for first name or last name. Would it be better to use a filter in this situation? If not, can someone please help me with the code.

Thanks,

gogirl
 
Well, if you've got the string already built:

strCriteria = "[FName] = '" & txtFName & "' AND [LName] = '" txtLName & "'"

Then you've got 3 ways of doing it...

Me.Filter = strCriteria
Me.FilterOn = True

OR

DoCmd.ApplyFilter strCriteria

OR

Me.RecordsetClone.FindNext strCriteria
Me.Bookmark = Me.RecordsetClone.Bookmark

any of these will work, but if you use the filter then you'll have to make sure to remove the filter if you want the users to be able to navigate through all the records. If there will be more than one record with the name, then a filter is probably the best way to go. The RecordsetClone will work, since I used "FindNext", but it's pretty much a preference issue. Kyle

[anakin] + [curse] = [vader2]
[anakin] + [amidala] = [lightsaber]
 
After reading your post again, I guess you'd make your criteria string like this:

Dim strResp as String
Dim strCriteria as String

strResp = Inputbox("Please Enter First or Last Name")

strCriteria = "[FName] = '" & strResp & "' OR [LName] = '" strResp & "'"
Kyle

[anakin] + [curse] = [vader2]
[anakin] + [amidala] = [lightsaber]
 
KyleS,

Thanks so much for your help!

Have a star.

Cara
 
Glad I could help!

And thanks for the recognition! Kyle

[anakin] + [curse] = [vader2]
[anakin] + [amidala] = [lightsaber]
 
KyleS,

I have another question. I am looking for someone named Johnson-Zepata but when I type in Johnson in the filter it doesn't bring them up. Is there anyway to add an asterick into the strCriteria so that from now on when I enter a name it will filter for everything behind it?
 
KyleS,

I have another question. I am looking for someone named Johnson-Zepata but when I type in Johnson in the filter it doesn't bring them up. Is there anyway to add an asterick into the strCriteria so that from now on when I enter a name it will filter for everything behind it?

Thanks,

Cara
 
This should work

strCriteria = "[FName] Like '" & strResp & "*' OR [LName] Like '" strResp & "*'"

Hope this helps!! Kyle

[pacman]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top