Hello All,
I have my submit button with the following code which should save the record when it gets to If Me.Dirty Then. When I step through the code it highlights the code Me.Dirty = False suggesting that it's saving it because then it goes to BeforeUpdate to CheckValidation (checking for errors) but there's nothing to validate because the record isn't saved in the table. I'm scratching my head because it was working fine and now it's not! This is the very first step in a long process to test and I can't get past the first part. Please help
Code:
Private bFailValidation As Boolean
Private tSave As Integer
Code:
Private Sub btnSubmitAndClose_Click()
Dim Cancel As Integer
Cancel = 0
tSave = 1
On Error GoTo ErrorHandler
If Me.Dirty Then
Me.Dirty = False
Else
Dim r As VbMsgBoxResult
r = MsgBox("Are you sure you want to submit with no changes?", vbYesNo, "Submit?")
If r = vbYes Then
CheckValidation Me, Cancel, bWO
bFailValidation = Cancel
If bFailValidation = False Then
UpdateData
End If
ElseIf Cancel = True Then
Exit Sub
End If
End If
If tSave = 0 Then
Me.Requery
Me.KeyPreview = False
End If
Me.Requery
Exit Sub
ErrorHandler: 'DEBUG
MsgBox "Submit ERROR: " & Err.Number & " " & Err.Description
End Sub
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrorHandler
If tSave = 0 Then 'Exit if no validation needed
Exit Sub
ElseIf tSave = 1 Then
CheckValidation Me, Cancel, bWO
bFailValidation = Cancel
' If bFailValidation = False Then
UpdateData
' End If
ElseIf tSave = 2 Then
Exit Sub
End If
Exit Sub
Exit Sub
ErrorHandler: 'DEBUG
MsgBox "BeforeUpdate ERROR: " & Err.Number & " " & Err.Description
End Sub