Quote:
Originally Posted by jlathem Can anyone suggest how I can keep a comment record from being created if the “Comment” text box is blank or only has blank spaces in the text box? Is there a VB script or something?? |
Note: Access uses VBA, not VB script, internally
In the form's Before Update event use something like this:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = False
' perform data validation
If Len(Trim(Nz(Me.txtComment,""))) < 1 Then
MsgBox "You must enter a comment.", vbCritical, "Data entry error..."
Cancel = True
End If
If Not Cancel Then
' passed the validation process
If Me.NewRecord Then
If MsgBox("Data will be saved, Are you Sure?", vbYesNo, "Confirm") = vbNo Then
Cancel = True
Else
' run code for new record before saving
End If
Else
If MsgBox("Data will be modified, Are you Sure?", vbYesNo, "Confirm") = vbNo Then
Cancel = True
Else
' run code before an existing record is saved
' example: update date last modified
End If
End If
End If
' if the save has been canceled or did not pass the validation , then ask to Undo changes
If Cancel Then
If MsgBox("Do you want to undo all changes?", vbYesNo, "Confirm") = vbYes Then
Me.Undo
End If
End If
End Sub