Hello, I have been trying to figure out why im getting the error 2169 save yes/no message when running a validation from the BeforeUpdate event. If I close the form I get the intendened pop up notifying me that there are fields that need filled in and am asked if I want to (yes) close without save and undo or (No) just continue editing and go to the control. If I select yes it undoes and exits the sub but if I select no it gives me the MS message 2169 "You cant save this record at this time"
and I select no and it sets focus to the control thats blank. How do I fix and why am I getting the 2169 message?
Thanks,
SoggyCashew.....
and I select no and it sets focus to the control thats blank. How do I fix and why am I getting the 2169 message?
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim blnError As Boolean
Dim strCtlMsg As String
Dim strCtrl As String
If Len(Me.txtVWI & vbNullString) = 0 Then
blnError = True
strCtlMsg = "Document Number, "
strCtrl = "txtVWI"
End If
If Len(Me.cboDepartment & vbNullString) = 0 Then
blnError = True
strCtlMsg = strCtlMsg & "Department, "
If strCtrl = "" Then
strCtrl = "cboDepartment"
End If
End If
If Len(Me.cboVWICategory & vbNullString) = 0 Then
blnError = True
strCtlMsg = strCtlMsg & "Categories, "
If strCtrl = "" Then
strCtrl = "cboVWICategory"
End If
End If
If Right(strCtlMsg, 2) = ", " Then
strCtlMsg = Left(strCtlMsg, Len(strCtlMsg) - 2)
End If
If blnError Then
If MsgBox("These required fields were not filled in: " & vbCrLf & _
strCtlMsg & vbCrLf & vbCrLf & _
"Do you wish to continue without filling in required fields?" & vbCrLf & _
"All data entered will be undone if YES is selected!", vbYesNo, "Incomplete Form") = vbYes Then
Me.Undo
Exit Sub
Else
Cancel = True
Me.Controls(strCtrl).SetFocus
End If
End If
End Sub
Thanks,
SoggyCashew.....