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

I need help with some code please

Status
Not open for further replies.

Introfield

Instructor
Apr 19, 2002
21
0
0
IT
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
 
How are ya Introfield . . . .

Here's a much eaiser way to do this:

On your [blue]Invoices Form[/blue], add a combobox. The [blue]RowSource[/blue] of the combobox will be a query or SQL that includes the CustomerID, Customer Name, and any other fields necessary for identification. The [blue]Bound[/blue] field of the combobox will be used as crireria for a query you'll design for the form. Here's a smaple SQL for the form including criteria for the combobox:
Code:
[blue]Select CustomerID, Name, FieldName?, FieldName?
From tblInvoices
Where CustomerID = Val(Forms![purple]InvoiceFormName[/purple]![purple]ComboboxName[/purple])[/blue]
This is just to give you an Idea of how this is going to work.

When a user makes a selection from the combobox, the combobox is going to [blue]Requery[/blue] the form with a single line in code of [blue]Me.Requery[/blue].

When the form is required, only the records that match the CustomerID in the combobox will be returned, and these will be the only records until you select another.

With that you'll be able to scan thru your invoices easily using the navigation buttons. First, Last, Step Forward/Backward.

cal.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top