Procedure If IsNull ... Then

I

If

I have the procedure below which applies to a form of introduction.
But if the user does not fill the field indicated by the error and
press the button (>*), access goes to the next record.

My Question:
Is it possible to use a procedure on this button (> *)?

My Procedure:

Private Sub Form_AfterUpdate()
If IsNull(Me![cmbName]) Then
MsgBox "Select a value for the 'Name' ", vbInformation, "Error"
Me![cmbName].SetFocus
Exit Sub
End If

.....

End Sub
 
G

Gerald Stanley

Any validation that you wish to invoke on your data at the form level prior
to new rows being added or existing rows being amended should take place in
the form's BeforeUpdate eventHandler. This eventHandler comprises a Cancel
parameter which should be set to True should the validation fail. You code
should look something like

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me![cmbName]) Then
MsgBox "Select a value for the 'Name' ", vbInformation, "Error"
Me![cmbName].SetFocus
Cancel = True
Exit Sub
End If

......

Hope This Helps
Gerald Stanley MCSD
 
I

If

Thanks for your answer.

I have that now and it's ok



Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

Dim strMessage As String

If IsNull(Me![cmbName]) Then
strMessage = strMessage & vbCrLf & "Select a value for the 'Name'
Me![cmbName].SetFocus
Cancel = True
End If

..... 'Others If IsNull ...

If Cancel = True Then
MsgBox (strMessage), vbInformation, " Erreur"
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source & vbCrLf
& Err.Description, , "FormName - Form_BeforeUpdate"
Resume Exit_Form_BeforeUpdate

End Sub



Gerald Stanley said:
Any validation that you wish to invoke on your data at the form level
prior
to new rows being added or existing rows being amended should take place
in
the form's BeforeUpdate eventHandler. This eventHandler comprises a
Cancel
parameter which should be set to True should the validation fail. You
code
should look something like

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me![cmbName]) Then
MsgBox "Select a value for the 'Name' ", vbInformation, "Error"
Me![cmbName].SetFocus
Cancel = True
Exit Sub
End If

.....

Hope This Helps
Gerald Stanley MCSD

If said:
I have the procedure below which applies to a form of introduction.
But if the user does not fill the field indicated by the error and
press the button (>*), access goes to the next record.

My Question:
Is it possible to use a procedure on this button (> *)?

My Procedure:

Private Sub Form_AfterUpdate()
If IsNull(Me![cmbName]) Then
MsgBox "Select a value for the 'Name' ", vbInformation, "Error"
Me![cmbName].SetFocus
Exit Sub
End If

.....

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top