Need Message on Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that has 2 text boxes with information that can be entered by
the user to locate all of the client information. (Client ID, Client SS#)

The user enters the information and the form is updated with all of the
client information and opens a subform with all of the authorization
information for that client.

The only problem is that if the client ID or SS# is not entered correctly
the first record from the client table pops up as the current record.

I would like to have a message that states "Record Not Found" pop up to warn
the user that this is not the record they are searching for.

Thanks

my code looks like:

Private Sub Combo12_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[PATIENT_ID] = " & Str(Nz(Me![Combo12], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Exit Sub

End Sub
 
Your code is very close to making this happen. I think you simply need an
'Else' block right after the 'If' that checks for the EOF. So unless I'm
missing something here, your code should look like this:

Private Sub Combo12_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[PATIENT_ID] = " & Str(Nz(Me![Combo12], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Else
MsgBox("Record Not Found")
End If
Exit Sub
End Sub

Hope that works for you. Good luck.

-ndalton
 
Had a bit of a problem with the code - error message that stated else without
if statement.

Played with it a little and got it to work as follows
Private Sub Combo12_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[PATIENT_ID] = " & Str(Nz(Me![Combo12], 0))
If rs.EOF Then MsgBox("Record Not Found")
Else Me.Bookmark = rs.Bookmark

End If
Exit Sub
End Sub

Thanks!

ndalton said:
Your code is very close to making this happen. I think you simply need an
'Else' block right after the 'If' that checks for the EOF. So unless I'm
missing something here, your code should look like this:

Private Sub Combo12_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[PATIENT_ID] = " & Str(Nz(Me![Combo12], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Else
MsgBox("Record Not Found")
End If
Exit Sub
End Sub

Hope that works for you. Good luck.

-ndalton


PetNetwork said:
I have a form that has 2 text boxes with information that can be entered by
the user to locate all of the client information. (Client ID, Client SS#)

The user enters the information and the form is updated with all of the
client information and opens a subform with all of the authorization
information for that client.

The only problem is that if the client ID or SS# is not entered correctly
the first record from the client table pops up as the current record.

I would like to have a message that states "Record Not Found" pop up to warn
the user that this is not the record they are searching for.

Thanks

my code looks like:

Private Sub Combo12_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[PATIENT_ID] = " & Str(Nz(Me![Combo12], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

Exit Sub

End Sub
 
Back
Top