D
D B Lawson
Guest
Here's a cracker! I have a form with subforms that are on tab controls (3 subforms). On a Close button I have some code to make sure that the user has completed all the required fields. If they haven't and the click to close the form anyway, the record is set to "Undo". This was working well, I thought, until I found some phantom records with no reason for them. I then discovered that if the user is mucking about, enters some data, clicks the tab controls, looks at the subforms (doesn't create any records within the subform) and then click's to close, the main record doesn't undo! Why! Anybody got any solutions to my problem? When stepping through the code, it looks as if the record is undoing, but it's not. Here is my code:
If (Me.cboJobType) = 1 Or Me.cboJobType = 4 And Not IsNull(Me.JDateEntered) Then
If IsNull(Me.cboLoggedBy) Or Me.JLoggedBy = 0 Then
stdResponse = MsgBox("You have not entered your name in the Logged By field." & vbCr & _
"This is a required field, do you want to complete it now?" & vbCr & vbCr & _
"Select YES to return and select your name." & vbCr & vbCr & _
"Select NO to exit the form WITHOUT SAVING the record.", _
vbYesNo + vbDefaultButton1, "Missing Data")
If stdResponse = vbNo Then '(Default)
Me.Undo
DoCmd.Close
Exit Sub
Else 'vbCancel
Me.cboLoggedBy.SetFocus
Exit Sub
End If
End If
'
End If
If (Me.cboJobType) = 1 Or Me.cboJobType = 4 And Not IsNull(Me.JDateEntered) Then
If IsNull(Me.cboLoggedBy) Or Me.JLoggedBy = 0 Then
stdResponse = MsgBox("You have not entered your name in the Logged By field." & vbCr & _
"This is a required field, do you want to complete it now?" & vbCr & vbCr & _
"Select YES to return and select your name." & vbCr & vbCr & _
"Select NO to exit the form WITHOUT SAVING the record.", _
vbYesNo + vbDefaultButton1, "Missing Data")
If stdResponse = vbNo Then '(Default)
Me.Undo
DoCmd.Close
Exit Sub
Else 'vbCancel
Me.cboLoggedBy.SetFocus
Exit Sub
End If
End If
'
End If