Hi Lars,
Try using the Form_BeforeUpdate procedure. Here is an example:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ProcError
Dim blnValidate As Boolean
blnValidate = Validate
If blnValidate = False Then
Cancel = True
Err.Number = acDataErrContinue
End If
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Form_BeforeUpdate event procedure..."
Resume ExitProc
End Sub
Private Function Validate() As Boolean
On Error GoTo ProcError
Validate = False 'Initialize return value
' Check for required field entries, if the form is dirty
If IsNull(cboProject) Then
MsgBox "Please Select a Project or click on the" & _
vbCrLf & "Undo button to discard all changes.", _
vbCritical, "Missing Required Value..."
cboProject.SetFocus
Exit Function
End If
If IsNull(txtRequestTitle) Then
MsgBox "Please Enter a Title or click on the" & _
vbCrLf & "Undo button to discard all changes.", _
vbCritical, "Missing Required Value..."
txtRequestTitle.SetFocus
Exit Function
End If
If IsNull(txtRaisedDate) Then
MsgBox "Please Enter the Date Raised or click on the" & _
vbCrLf & "Undo button to discard all changes.", _
vbCritical, "Missing Required Value..."
txtRaisedDate.SetFocus
Exit Function
Else
If Date < txtRaisedDate Then
MsgBox "You must not enter a future date", _
vbCritical, "Incorrect Date Entry..."
txtRaisedDate = Null
txtRaisedDate.SetFocus
Exit Function
End If
End If
Validate = True 'If we get this far, then all validation checks passed.
Me.txtLastUpdate = Date '<--If you have a LastUpdated field.
' Note: This textboxcan be a
hidden text box.
ExitProc:
Exit Function
ProcError:
Select Case Err.Number
Case 2110
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Validate procedure..."
End Select
Validate = False
Resume ExitProc
End Function
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________