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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do not close form if subform is not done

Status
Not open for further replies.

Dophia

Technical User
Jul 26, 2004
263
CA
Hi Everyone:

I want to ensure that the subform is completed by users before closing the main form. This works, but if someone opens the form in error and then wants to close it, they can't since the subform is not complete.

Can anyone help?

I current have this code on the main form's unload.

Private Sub Form_Unload(Cancel As Integer)
DoCmd.SetWarnings False
If Me! SubfrmAssessment_Details_Admission.Form.RecordsetClone.Reco
rdCount = 0 Then
MsgBox "Please enter an assessment first"
Cancel = True
End If
End Sub

Thanks, Sophia
 
This might not be what you're looking for, but if you modify your code to use a while loop instead of an if statement to check the subform, and use a pop-up mini form to tell the user that the "Form is closing..." so they know to wait. Set a boolean variable to true in the Form_Unload then move your existing code to Form_Deactivate.

Option Compare Database
Global fUSER_CLOSE As Boolean

Private Sub Form_Unload(Cancel As Integer)
fUSER_CLOSE = True
End Sub

Private Sub Form_Deactivate(Cancel As Integer)
DoCmd.SetWarnings False
If Me!SubfrmAssessment_Details_Admission.Form.RecordsetClone.RecordCount = 0 Then
If fUSER_CLOSE Then
MsgBox "Form is closing..." 'Or create a form and use DoCmd.OpenForm "frmClosingMsg"
Do While (Me!SubfrmAssessment_Details_Admission.Form.RecordsetClone.RecordCount = 0)
Loop
End If
Else
MsgBox "Please enter an assessment first"
Cancel = True
End If
DoCmd.SetWarnings True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top