I have a single record form with contract details and a subform where I enter some additional information. The main form has a command button to close it.
I need to check 2 controls on closing(one in main form and one in subform) and if some conditions are met a Yes/No MsgBox should appear. If the user presses "Yes", the form closes, if he presses "No" the form remains open.
So far I have this:
Private Sub Form_Unload(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("It looks like this contract is fixed. Would you like to edit the final price?", vbYesNo, "Database Information")
If Me![fixed price] = 0 And Me![Fixation Orders Subform1].Form!Text38 = "Final Fixed Price" Then
Cancel = True And Response
If Response = vbYes Then
Cancel = True
Else
Cancel = False
End If
Else
Cancel = False
End If
End Sub
Problems: Before I defined "response" the MsgBox appeared correctly but the form closed anyway. After I defined it to use it in the second "If":
- The message box appears no matter what
- The form closes either I press "Yes" or "No"
Additionally, after I solve this, on which event should I put this code to chack the conditions also when I go to next record? Thanks in advance.
Cancel = Response=vbYesinstead ofCancel = True And Responsethe AND with a true, means that cancel will be the same as the other side of the AND.TRUE and today=Wednesday, only ever need to check the day for example. Looking at your if, it doesn't seem logical, you set the Cancel, try to, then base it on the msgbox decision. Before end sub, just putcancel=response=vbYesor which ever way you want the decision - Nathan_SavResponse. That's not nested in anIfstatement. What exactly is the lineCancel = True And Responsesupposed to do? Do you haveOption Expliciton? - Erik AOption Explicithere, this page gives a quick explanation why you would want to use it. If you're having troubles with something, turningOption Expliciton often helps. - Erik A