I have created a form to allow users to add a new record and/or search for an existing record based on SSN. If the SSN the user enters into SrchID_text is found, the form is populated and a message appears telling the user that the record exists and they can edit existing information or add new information. If the SSN is not found, a new record is supposed to be created and a message appears telling the user that no match was found and they can begin entering data.
My problem occurs when there are no records in the database.
How do I get around this?
Please see code below:
My problem occurs when there are no records in the database.
How do I get around this?
Please see code below:
Code:
Private Sub SrchID_But_Click()
Dim strStudentRef As String
Dim strSearch As String
'Check SrchID_text for Null value or Nill Entry first.
If IsNull(Me![SrchID_Text]) Or (Me![SrchID_Text]) = "" Then
MsgBox "Please enter a SSN to search for!", vbOKOnly, "Invalid Search Criterion!"
Me!SrchID_Text.SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into SrchID_text
'and evaluates this against values in SSN
DoCmd.ShowAllRecords
DoCmd.GoToControl ("SSN")
DoCmd.FindRecord Me![SrchID_Text]
SSN.SetFocus
strStudentRef = SSN.Text
SrchID_Text.SetFocus
strSearch = SrchID_Text.Text
'If matching record found fills in data and
'sets focus on participant's first name and
'clears search control
If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch & vbCrLf & " " & vbCrLf & "Please edit or add data as needed.", , "Existing Record Found"
F_Name.SetFocus
SrchID_Text = ""
'If value not found sets SSN equal to searched SSN and
'informs user to begin entering data and sets focus on
'F_Name
Else
MsgBox "Match Not Found For: " & strSearch & vbCrLf & " " & vbCrLf & "Please begin entering data for this new participant.", _
, "New Participant!"
DoCmd.GoToRecord , , acNewRec
SSN.SetFocus
SSN.Text = strSearch
LWIA_Combo.SetFocus
End If
End Sub
Comment