Command Find not working when Form is Subform

MHBear21

New member
Local time
Today, 00:47
Joined
Jul 26, 2011
Messages
8
Hello, I have a command button to find an invoice number that works the way it should when I test it a single form. When the same form is moved to a subform of another form the find dosen't seem to do anything.

I get the Msgbox and can input the number but then it just sets the focus to the Invoice_No field without finding anything.

Private Sub cmdFind_Click()
Dim InvoiceToFind As String
Me.Invoice_No.SetFocus

InvoiceToFind = _
InputBox("Enter the Invoice Number", "Find Invoice")
On Error Resume Next
DoCmd.FindRecord InvoiceToFind
If InvoiceToFind <> Invoice_No Then
MsgBox "The record wasn't found." & Chr(10) & "Please try again."
End If
End Sub

Do I have to do something different with the code?

Thanks in advance
 
If your button is on the Main form and you wish to search a Subform, you will need to insert some code to set Focus on the Subform prior to firing the FindRecord command.

Check the link here for the correct Syntax for referring to a Subform and it properties from various relative locations.
 
John, the find button is in the subform not the main form.

I am trying a find command on the Main form and was able to modify the SetFocus part of the code to:

Me.subfrmNew_Invoice.SetFocus
Me.subfrmNew_Invoice!Invoice_No.SetFocus

Now it looks in the right place, but no matter what value I input it can't find it. Just gives me the MsgBox part of the code "record wasn't found". Any Ideas?


Hello, I have a command button to find an invoice number that works the way it should when I test it a single form. When the same form is moved to a subform of another form the find dosen't seem to do anything.

I get the Msgbox and can input the number but then it just sets the focus to the Invoice_No field without finding anything.

Private Sub cmdFind_Click()
Dim InvoiceToFind As String
Me.Invoice_No.SetFocus

InvoiceToFind = _
InputBox("Enter the Invoice Number", "Find Invoice")
On Error Resume Next
DoCmd.FindRecord InvoiceToFind
If InvoiceToFind <> Invoice_No Then
MsgBox "The record wasn't found." & Chr(10) & "Please try again."
End If
End Sub

Do I have to do something different with the code?

Thanks in advance
 

Users who are viewing this thread

Back
Top Bottom