G
Guest
I've created a search button on a form to locate a record. The ides is to
the record# and press the search button and the record in a form is returned.
The code that I have is listed below. I receive a run time error 424
Object Required when I use it. Would someone please give me a pointer on
why t is not working, please.
Private Sub cmdSearch_Click()
Dim strInvoiceNumber As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
DoCmd.ShowAllRecords
DoCmd.GoToControl ("InvoiceNum")
DoCmd.FindRecord Me!txtSearch
InvoiceNum.SetFocus
strnvoiceNumber= InvoiceNum.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control
If strInvoiceNumber = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
InvoiceNum.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub
the record# and press the search button and the record in a form is returned.
The code that I have is listed below. I receive a run time error 424
Object Required when I use it. Would someone please give me a pointer on
why t is not working, please.
Private Sub cmdSearch_Click()
Dim strInvoiceNumber As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
DoCmd.ShowAllRecords
DoCmd.GoToControl ("InvoiceNum")
DoCmd.FindRecord Me!txtSearch
InvoiceNum.SetFocus
strnvoiceNumber= InvoiceNum.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control
If strInvoiceNumber = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
InvoiceNum.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub