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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find a record using code 1

Status
Not open for further replies.

TheKidLarose

Programmer
Feb 20, 2003
7
CA
I have been working at this for a over a week and I am baffled. I need help. I am new at coding so this maybe very basic for others but certainly complicated for me. I am trying to create code to take the information from a text box on a form entered by a user and locate records that match the first string they enter or a name they enter. I then want to transfer the record to the main form called frmGuest so that user can view their information.

The form that I've made up frmSearchGuest is based on a query qrySearchGuest which is made up of 3 fields, LastName, FirstName and ID. This query is based on a table named People. The form frmSearchGuest has a text field named bxSearch, a go button named btnSearch and an update button to update the information queried to a form named frmGuests. It also has 2 fields, LastName and FirstName which shows the name of all my guests

This is the code that I use to locate a record. It works to some extent but does not find the record that the user has specified


Private Sub btnGoSearch_Click()
Dim LN As String,

LN = "LastName Like '" & Me.bxSearch.Value & "*'"
Me.LastName.SetFocus
DoCmd.FindRecord LN, acEntire, False, acSearchAll, True, acCurrent, True

End Sub

Help

Tks

Denis
 
Because you are a little inexperienced with ACCESS you have as we all have done before you made something simple into a complicated process.

If I may make a suggestion. This can all be cone on one form. Your frmGuest form can have a text box where you enter a name, string, or partial string of characters that can search for all guests with that as the beginning of their last name. Now how to get your started with this is the problem.

For the time being let's dump the first form and concentrate on the second form frmGuest.

1. Create a new textbox and call it bxSearch as you already did on the other form.
2. Create a command button with a caption of Search. In the AfterUpdate Event Procedure put the following code:

Me.Filter = "tblPeople.LastName like '" & Me![bxSearch] & "*'"
Me!Filteron = True
Me.Requery

This should requery, with a form filter,the form frmGuest to display all Guest records that have a LastName starting with the value in the bxSearch. You can use the Navigation buttons to walk through the filtered records to see if the search was appropriately successful.

Give this a try first of all to see if this is what you want and then we can refine a little to include a Reset button to clear the search back to all Guests.

Bob Scriver
 
Sorry, typo. #2 should read:
2. Create a command button with a caption of Search. In the On Click Event Procedure put the following code:
Bob Scriver
 
Thanks Bob

I got it to work using your info. I really appreciate it

Denis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top