QueryClose problem

K

Keith74

Hi All

I've two forms i'm toggling between using this code:

frmMain
Private Sub cmdClient_Click()

Unload frmMain
frmClient.Show

End Sub

frmClient
Private Sub cmdCancel_Click()

Dim varResponse As Variant

If blnChangedData = True Then
varResponse = MsgBox("You have changed data without saving" &
Chr(13) & Chr(13) & _
"Do you wish to exit the form now?", vbYesNo)
If varResponse = vbNo Then
Exit Sub
End If
End If

Unload frmClient
frmMain.Show

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)

Dim varResponse As Variant
If CloseMode = vbFormControlMenu Then
If blnChangedData = True Then
varResponse = MsgBox("You have changed data without saving"
& Chr(13) & Chr(13) & _
"Do you wish to exit the form now?", vbYesNo)
If varResponse = vbNo Then
Exit Sub
End If
End If

Unload Me
frmMain.Show
End If
End Sub

If I use the command buttons to go between the forms everything works
fine. If i close frmClient via the red cross, when i try to open the
form again from frmMain i get the error "run time error 400 form
already displayed can't show modally".
Anyone have any idea what the problem is? I'm running XP and excel
2003 sp2 is thats any help.

Thanks

keith
 
K

Keith74

Thanks for the reply Pranav. It solves the error problem, but now when
the frmClient userform displays for the second time, clicking the red
cross doesn't run the queryclose event.
 
K

Keith74

Ah, found a solution, adding a line to the query close event works

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)


Dim varResponse As Variant
If CloseMode = vbFormControlMenu Then
If blnChangedData = True Then
varResponse = MsgBox("You have changed data without
saving"
& Chr(13) & Chr(13) & _
"Do you wish to exit the form now?", vbYesNo)
If varResponse = vbNo Then
Exit Sub
End If
End If


Unload Me
set frmClient = nothing '<------new line
frmMain.Show
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