I have the below vba that I use on my form event "On Click". The form is called "ActionPlan" and it works perfectly
My question is as follows....I did not want the search command on the "ActionPlan" form. I created another form called "frmSearch" and under "On Click" event I embedded the above code. I just cant get it to work.
I want to type the Seq_Number in the "txtSearch" unbound field and click Search button and the result is
ActionPlan form opens up with the info populated in the fields related to the Seq_Number and ofcourse the frmSearch will close
Thanks for the help
Code:
Private Sub cmdSearch_Click()
On Error GoTo Err_cmdSearch_Click
' Define
Dim strNumRef As String
Dim strSearch As String
' Check if the field "txtSearch" on the form is empty/blank
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
DoCmd.ShowAllRecords
DoCmd.GoToControl ("Seq_Number")
DoCmd.FindRecord Me!txtSearch
Seq_Number.SetFocus
strNumRef = Seq_Number.SetFocus.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
If strNumRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
txtSearch = ""
txtSearch.SetFocus
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
DoCmd.GoToRecord , , acNewRec
End If
Exit_cmdSearch_Click:
Exit Sub
' Closes Form after being used
DoCmd.close acForm, "frmSearch"
' Takecare of error
Err_cmdSearch_Click:
'MsgBox Err.Description
Resume Exit_cmdSearch_Click
End Sub
My question is as follows....I did not want the search command on the "ActionPlan" form. I created another form called "frmSearch" and under "On Click" event I embedded the above code. I just cant get it to work.
I want to type the Seq_Number in the "txtSearch" unbound field and click Search button and the result is
ActionPlan form opens up with the info populated in the fields related to the Seq_Number and ofcourse the frmSearch will close
Thanks for the help