Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form validation giving MS message 2169

Status
Not open for further replies.

oxicottin

Programmer
Jun 20, 2008
353
US
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?

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.....
 
How are ya oxicottin . . .

Try:
Code:
[blue] Me(strCtrl).SetFocus[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks AceMan, I tried your sugestion but still it gives me the same results. What I want to do is a Data verification of one text box and two combo boxes on my form and everything I have tried isnt working. I have searched the net and found several diferent ways to do this and they all give different results but cant get it to work correctly with my form. Any sugestions?

Thanks,
Chad

Oh, AceMan if your a admin can you change my status from Programer to Newbie or novice? I acidently selected that when setting up my account a long time ago and cant figure out how to change it.

Thanks,
SoggyCashew.....
 
oxicottin . . .

Sorry to get back so late!.

I did some testing and as expected your [blue]problem will only occur when a user hits the form close button[/blue]. This is because access is closing the form object and apparently has priority in control over [blue]Cancel=True[/blue]. It is actually the [blue]Cancel=True[/blue] line that causes the system message to popup, giving you the options to close and lose the record or abort closing the form.

To my knowledge there's no way to detect if the close button was clicked. Even if you could it would be academic since access has priority! Its not a bad message, just not custom, and it does do the job.

Only way around it is make sure users know how to save a record or perhaps you could install a [blue]save button[/blue] and get them use to that.

Wish I had better news ...


See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks for the reply... I figured I couldn't get rid of it....

Thanks,
SoggyCashew.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top