Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default unload userform from within one of that form's beforeupdate events?

I'm still pretty much a novice excel programmer; I've been stumped
with the following question for a day, and I haven't seen in addressed
in the groups. Please forgive me if it has.

I've got a userform with a control called "TextBoxNoOfFilters". In a
simplified version of the problem, I need to make sure that a number
is entered, and that that number is NOT 2. If the user does enter 2,
I'd like to immediately indicate this elsewhere in the workbook (with
textboxes) and then exit the userform.

When I call the Unload Userform command, it works, but the unload
process seems to call the BeforeUpdate procedure again. Therefore, if
the user enters 2 and confirms it, the userform disappears and then
they get another msgbox asking them to confirm their entry.

I can't figure out why the unload calls the beforeupdate again, or how
to avoid that re-call.

A sketch of the code follows. Any thoughts would be most appreciated.

Thanks,
Andrew H.


Private Sub TextBoxNoOfFilters_BeforeUpdate(ByVal Cancel As
MSForms.ReturnBoolean)

If IsNumeric(TextBoxNoOfFilters) Then
If TextBoxNoOfFilters = 2 Then

msg = "Are you sure you want to enter 2?"
response = MsgBox(prompt:=msg, _
Buttons:=vbQuestion + vbYesNo, _
Title:="Confirm 2 Filters")

If response = vbYes Then
msg = "New warning message goes here"
MsgBox prompt:=msg, Buttons:=vbExclamation
'call a sub to put some text boxes on the worksheets
Unload Userform
End If

End if
Else
msg = "Please enter a number"
MsgBox prompt:=msg, Buttons:=vbExclamation
Cancel = True
TextBoxNoOfFilters = TextBoxNoOfFilters.BoundValue
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 196
Default unload userform from within one of that form's beforeupdate events?

Try this: (use it as i have done it. The message box
prompts are not required). Do not use Unload, use End.
Unload is used if the userform is a second form. It
unloads the second form to show the main form but even
still, it is best to use the userform.hide instead.
The "End" statement unloads all forms and frees up memory.


'Command button named cmdClose
sub cmdClose_Click()
End
end sub


Private Sub TextBoxNoOfFilters()
dim response
dim msg
If IsNumeric(TextBoxNoOfFilters.text) Then
'Yes, it's a number.
If TextBoxNoOfFilters.text = 2 Then
'Yes it's 2.
msg = "Are you sure you want to enter 2?"
response = MsgBox(msg,vbQuestion + vbYesNo, _
"Confirm 2 Filters")

If response = vbYes Then
msg = "New warning message goes here"
MsgBox msg, vbExclamation
'call a sub to put some text boxes on the
worksheets
cmdClose_Click
End If
End if
else

msg = "Please enter a number value only."

MsgBox msg, vbExclamation
End Sub


regards

Mark
See some of my handiwork at
http://www.geocities.com/excelmarksway

-----Original Message-----
I'm still pretty much a novice excel programmer; I've

been stumped
with the following question for a day, and I haven't seen

in addressed
in the groups. Please forgive me if it has.

I've got a userform with a control

called "TextBoxNoOfFilters". In a
simplified version of the problem, I need to make sure

that a number
is entered, and that that number is NOT 2. If the user

does enter 2,
I'd like to immediately indicate this elsewhere in the

workbook (with
textboxes) and then exit the userform.

When I call the Unload Userform command, it works, but

the unload
process seems to call the BeforeUpdate procedure again.

Therefore, if
the user enters 2 and confirms it, the userform

disappears and then
they get another msgbox asking them to confirm their

entry.

I can't figure out why the unload calls the beforeupdate

again, or how
to avoid that re-call.

A sketch of the code follows. Any thoughts would be most

appreciated.

Thanks,
Andrew H.


Private Sub TextBoxNoOfFilters_BeforeUpdate(ByVal Cancel

As
MSForms.ReturnBoolean)

If IsNumeric(TextBoxNoOfFilters) Then
If TextBoxNoOfFilters = 2 Then

msg = "Are you sure you want to enter 2?"
response = MsgBox(prompt:=msg, _
Buttons:=vbQuestion + vbYesNo, _
Title:="Confirm 2 Filters")

If response = vbYes Then
msg = "New warning message goes here"
MsgBox prompt:=msg, Buttons:=vbExclamation
'call a sub to put some text boxes on the

worksheets
Unload Userform
End If

End if
Else
msg = "Please enter a number"
MsgBox prompt:=msg, Buttons:=vbExclamation
Cancel = True
TextBoxNoOfFilters = TextBoxNoOfFilters.BoundValue
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
How can I expose the TextBox BeforeUpdate event to my user class? bereid Excel Discussion (Misc queries) 0 November 30th 05 05:00 PM
IeTimer events not working in modeless Userform? Ed[_18_] Excel Programming 0 August 3rd 04 04:21 PM
BeforeUpdate and Cancel Brad Excel Programming 0 May 10th 04 09:06 PM
BeforeUpdate event for Combo box Brad Excel Programming 2 May 7th 04 06:22 PM
UserForm Events Nigel[_6_] Excel Programming 1 February 22nd 04 12:19 PM


All times are GMT +1. The time now is 10:15 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"