Errror Message

  • Thread starter Thread starter Les
  • Start date Start date
L

Les

I have a Form which requires 2 of the Fields to have entries before the user
can move to the next record or exit.

What I would like to do is to use an Msgbox if these are not completed
instructing the user to complete the entries.

I have put a Msgbox on the forms On Error contol but the default message
appears afterwards. Can you tell me how to get round this.

Thanks

Les
 
You can use the BeforeUpdate event of the form the update occurs or you can
use the Error event of the form.

Here is some sample code for the BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.CustNAme) Then
MsgBox "bMust enter Custname"
Me.CustNAme.SetFocus
Cancel = True
ElseIf IsNull(Me.City) Then
MsgBox "bMust enter City"
Me.City.SetFocus
Cancel = True
End If
End Sub

In the Error event of the form you can test the value of the DataErr
parameter using the Error event of the form. Then set Response =
acDataErrContinue when you've handled known error conditions.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
MsgBox DataErr & vbCrLf & Error(DataErr)
Select Case DataErr
Case 3314
If IsNull(Me.CustNAme) Then
MsgBox "Must enter Custname"
Me.CustNAme.SetFocus
Response = acDataErrContinue
ElseIf IsNull(Me.City) Then
MsgBox "Must enter City"
Me.City.SetFocus
Response = acDataErrContinue
End If
End Select
End Sub
 
Thanks Sandra that works fine.


Sandra Daigle said:
You can use the BeforeUpdate event of the form the update occurs or you can
use the Error event of the form.

Here is some sample code for the BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.CustNAme) Then
MsgBox "bMust enter Custname"
Me.CustNAme.SetFocus
Cancel = True
ElseIf IsNull(Me.City) Then
MsgBox "bMust enter City"
Me.City.SetFocus
Cancel = True
End If
End Sub

In the Error event of the form you can test the value of the DataErr
parameter using the Error event of the form. Then set Response =
acDataErrContinue when you've handled known error conditions.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
MsgBox DataErr & vbCrLf & Error(DataErr)
Select Case DataErr
Case 3314
If IsNull(Me.CustNAme) Then
MsgBox "Must enter Custname"
Me.CustNAme.SetFocus
Response = acDataErrContinue
ElseIf IsNull(Me.City) Then
MsgBox "Must enter City"
Me.City.SetFocus
Response = acDataErrContinue
End If
End Select
End Sub


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

I have a Form which requires 2 of the Fields to have entries before
the user can move to the next record or exit.

What I would like to do is to use an Msgbox if these are not
completed instructing the user to complete the entries.

I have put a Msgbox on the forms On Error contol but the default
message appears afterwards. Can you tell me how to get round this.

Thanks

Les
 
Back
Top