Check by leaving frame

B

Bert

I have 2 frames on a dialogbox. When leaving the first
frame there is a check whether the variable
txtHoofdopsteller is empty or not. The frame must not been
abandoned when the named variable is empty unless......
there was a click on the commandbutten Cancel.
When there was a click on the commandbutton Cancel, a
check takes place whether is is allowed to leave the
frame. In the code of the frame I try to check if there
was a click on Cancel.
This is my code:
Private Sub fraOmslagpagina_Exit(ByVal Cancel As
MSForms.ReturnBoolean)

'Obligate input of this field
If frmPvAconops.cmdAnnuleren <> 0 Then
If Trim(Me.txtHoofdopsteller) = "" Then
Cancel = True
MsgBox "Vul de naam van de opsteller in. Je kunt
hem later weer wijzigen."
Exit Sub
End If
Else
Unload Me
ActiveDocument.Close SaveChanges = False
End
End If

End Sub

If there is a click on Cancel, the dialogbox unloads and
the document closes (=wanted result). But, when the
variables are filled in and the frame is left, the
dialogbox also unloads and the document closes (= not
wanted result!).

What is wrong in my code?

Thanks for your help.

Greets,

Bert
 
D

DA

Hi Bert

I assume that your "cmdAnnuleren" is the actual Cancel button.

I am also assuming that your Cancel button is outside of the frame.
The problem with this is that the frame exit event is triggered before
the button, so the cancel button value is always going to be 0.

If all the above assumptions are correct, I got your sample code to
work by placing the exit logic into the Cancel button _click() event.
BTW - you would have to dispense with the (If
frmPvAconops.cmdAnnuleren <> 0) check, otherwise your routine is
always going to exit when the user leaves the frame.

Hope that helps..
Dennis

Example:
--------
Private Sub cmdAnnuleren_Click()

If Trim(Me.txtHoofdopsteller) = "" Then
MsgBox "Vul de naam van de opsteller in. Je kunt "
Exit Sub
Else
Unload Me
ActiveDocument.Close SaveChanges = False
End
End If
End Sub

'-----
Private Sub fraOmslagpagina_Exit(ByVal Cancel As
MSForms.ReturnBoolean)

If Trim(Me.txtHoofdopsteller) = "" Then
MsgBox "Vul de naam van de opsteller in. Je kunt "
Exit Sub
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top