I need to write a custom error message for a before update procedure

lefty1324

New member
Local time
Today, 11:24
Joined
Nov 12, 2012
Messages
4
I have a form with fields last name, first name, is Adjuster active (check for yes) and adjuster email. I have the before update to not allow the record to be submitted if there are blanks but I am unsure how to write the VBA to give the error messages to tell the user to fill in the blank fields.

Any help would be appreciated
 
Just do a search on this forum, this topic has been handled numerous times.
 
You could try something along the lines of ...

Code:
Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim strMessage as String

strMessage = vbNullString

If Len(Me.fieldXXX & vbNullString) = 0 Then
  strMessage = "fieldXXX" ' Name of the control on the form
  Goto updateEnd
Endif

If Len(Me.fieldYYY & vbNullString) = 0 Then
  strMessage = "fieldYYY"
  Goto updateEnd
Endif

...
more tests
...


updateEnd:
If strMessage <> vbNullString Then
  Me.Controls(strMessage).SetFocus ' Put focus on thefirst empty control

  strMessage = "Field '" & strMessage & "' should not be left blank."
  msgBox strMessage, vbCritical + vbOkOnly, "Mandatory field warning"

  Cancel = TRUE ' Cancel the update
Endif
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom