InterGladiator
Registered User.
- Local time
- Today, 09:50
- Joined
- Apr 20, 2006
- Messages
- 20
Hi,
I have a text box and a button. The user types an order number into the text box, pushes the button and the VB code finds the appropriate record and makes it the active record. Now, how to provide a user with an error message if the record was not found (because he typed in a non-existing order number)? Could you, please, complete my code? Here is my code:
Private Sub SearchButton_Click()
Dim CheckLength As String
Dim ErrorText As String
' Check if the user has entered an order number
If Nz(Me.SearchBox.Value) < "0" Then
ErrorText = MsgBox("You didn't provide an order number", vbOKOnly, "Error!")
Else
' The order number must have 13 characters long
CheckLength = Me.SearchBox.Value
If Len(CheckLength) = 13 Then
Me![Kits Subform].SetFocus
Me![Kits Subform].Form.KitOrdNo.SetFocus
Application.Echo False
DoCmd.FindRecord Me.SearchBox.Value, acEntire, False, acSearchAll, False, acCurrent, True
Application.Echo True
' An error message should be showed here if there was no match.
Else
ErrorText = MsgBox("Order number must consist of 13 characters", vbOKOnly, "Error!")
End If
End If
End Sub
Thank you,
Attila
I have a text box and a button. The user types an order number into the text box, pushes the button and the VB code finds the appropriate record and makes it the active record. Now, how to provide a user with an error message if the record was not found (because he typed in a non-existing order number)? Could you, please, complete my code? Here is my code:
Private Sub SearchButton_Click()
Dim CheckLength As String
Dim ErrorText As String
' Check if the user has entered an order number
If Nz(Me.SearchBox.Value) < "0" Then
ErrorText = MsgBox("You didn't provide an order number", vbOKOnly, "Error!")
Else
' The order number must have 13 characters long
CheckLength = Me.SearchBox.Value
If Len(CheckLength) = 13 Then
Me![Kits Subform].SetFocus
Me![Kits Subform].Form.KitOrdNo.SetFocus
Application.Echo False
DoCmd.FindRecord Me.SearchBox.Value, acEntire, False, acSearchAll, False, acCurrent, True
Application.Echo True
' An error message should be showed here if there was no match.
Else
ErrorText = MsgBox("Order number must consist of 13 characters", vbOKOnly, "Error!")
End If
End If
End Sub
Thank you,
Attila