My problem occurs when there are no records in the database.
How do I get around this?
Please see code below:
Expand|Select|Wrap|Line Numbers
- 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