Introfield
Instructor
The following code provides a search facility on a DB I created some time ago. I need to perform an almost identical task now but am having trouble editing the code to suit. Sure it will be simple - but then, so am I.
This one enables the user to search for a Doctor by name, and if there is more than one doctor with the same name they can keep hitting "find next" until they find the one they're looking for. What I need now is to be able to search through invoices by customer name (therefore there will be many records with a matching CustomerID and that's why this code is inappropriate). I want the "find next" button to use the caption Find Next until the user reaches the last matching record, then the caption should change to read "no more"
Private Sub Find_Next_Click()
Dim DR As String
DR = DoctorId 'save value of DoctorId
SName.SetFocus 'move cursor to SName control
DoCmd.FindRecord (SName), , , , , , False 'find the record
[Find Next].SetFocus 'move cursor back to the find next button
If DoctorId = DR Then 'if same record is on screen (no more with same name)
[Find Next].Caption = "No more" 'change the button text
End If
End Sub
Private Sub Find_Next_LostFocus()
[Find Next].Caption = "Find Next"
End Sub
This one enables the user to search for a Doctor by name, and if there is more than one doctor with the same name they can keep hitting "find next" until they find the one they're looking for. What I need now is to be able to search through invoices by customer name (therefore there will be many records with a matching CustomerID and that's why this code is inappropriate). I want the "find next" button to use the caption Find Next until the user reaches the last matching record, then the caption should change to read "no more"
Private Sub Find_Next_Click()
Dim DR As String
DR = DoctorId 'save value of DoctorId
SName.SetFocus 'move cursor to SName control
DoCmd.FindRecord (SName), , , , , , False 'find the record
[Find Next].SetFocus 'move cursor back to the find next button
If DoctorId = DR Then 'if same record is on screen (no more with same name)
[Find Next].Caption = "No more" 'change the button text
End If
End Sub
Private Sub Find_Next_LostFocus()
[Find Next].Caption = "Find Next"
End Sub