Procedure If IsNull ... Then

  • Thread starter Thread starter If
  • Start date Start date
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
 
Use the BeforeUpdate event of the form, and cancel it if you do not want the
record to be saved:

Private Sub Form_BeforeUpdate()
If IsNull(Me![cmbName]) Then
Cancel = True
MsgBox...
 
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



Allen Browne said:
Use the BeforeUpdate event of the form, and cancel it if you do not want
the record to be saved:

Private Sub Form_BeforeUpdate()
If IsNull(Me![cmbName]) Then
Cancel = True
MsgBox...

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

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
 
Back
Top