Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default QueryClose problem

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default QueryClose problem

Hi,

In my opinion instead of using UNLOAD use Form.Hide

HTH,
--
Pranav Vaidya
VBA Developer
PN, MH-India
If you think my answer is useful, please rate this post as an ANSWER!!


"Keith74" wrote:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default QueryClose problem

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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default QueryClose problem

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default QueryClose problem

HI Keith

That's cool
--
Pranav Vaidya
VBA Developer
PN, MH-India
If you think my answer is useful, please rate this post as an ANSWER!!


"Keith74" wrote:

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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Userform Queryclose and Unload problem Dave Ramage Excel Programming 3 March 8th 07 07:39 PM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


All times are GMT +1. The time now is 05:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"