Starbuck67
asked on
Access 2007 FindRecord Macro does not work
I have a database of people and wish to go to a particular record. I have an unbound text box (FindLname) and a button that when I push it does the following...
1. Goes to the field LName
2. Goes to the last record
3. Then uses FindRecord to seach for a record that begins with the value in the text box (FindLname).
Currently only steps 1 and 2 work. Strangely, at one point, this macro did work.
Access-2007-2-8-15.jpg
1. Goes to the field LName
2. Goes to the last record
3. Then uses FindRecord to seach for a record that begins with the value in the text box (FindLname).
Currently only steps 1 and 2 work. Strangely, at one point, this macro did work.
Access-2007-2-8-15.jpg
ASKER
I deleted the go to last record portion. I suppose there must have been some reason for that, but I can't remember.
Unfortunately deletion of that line did not make a difference. The macro just takes me to the first record and sits there.
Instead of using the the location statement for "Find What" I just substituted some text. With the text, everything works fine. So, there must be something going on with the location statement, but I can't figure it out
Unfortunately deletion of that line did not make a difference. The macro just takes me to the first record and sits there.
Instead of using the the location statement for "Find What" I just substituted some text. With the text, everything works fine. So, there must be something going on with the location statement, but I can't figure it out
Oh,
Your "Match" argument is set to "Start of Field"...
Change it to: "Any Part Of Field"
Your "Match" argument is set to "Start of Field"...
Change it to: "Any Part Of Field"
...because if you type your search wrong (bad spelling) the macro will just sit there, ...as you state.
Because there are no matches.
FWIW, a very similar Macro works just fine for me...
See the attached sample db
Database65.mdb
Because there are no matches.
FWIW, a very similar Macro works just fine for me...
See the attached sample db
Database65.mdb
Try using an unbound combobox instead, filled with the key field (usually in an invisible column) and the first and last name. This is the boilerplate code for the AfterUpdate event of the combobox (use either the numeric or text line, depending on the key field):
Private Sub cboSelect_AfterUpdate()
'Created by Helen Feddema 29-Apr-2011
'Last modified by Helen Feddema 29-Apr-2011
On Error GoTo ErrorHandler
Dim strSearch As String
'For text IDs
strSearch = "[______ID] = " & Chr$(39) & Me.ActiveControl.Value _
& Chr$(39)
'For numeric IDs
strSearch = "[______ID] = " & Me.ActiveControl.Value
'Find the record that matches the control
Me.Recordset.FindFirst strSearch
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in " & Me.ActiveControl.Name & " procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(Remove that section of the macro and see what happens)
All that is needed is to move to the matching record.
I don't see anything wrong with the Find record portion of the macro...
Are you sure you spelled the names properly?, Are you sure none of the objects were renamed?
JeffCoachman