ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Call a Control_Click Event when UserForm is Initialized (https://www.excelbanter.com/excel-programming/403303-call-control_click-event-when-userform-initialized.html)

RyanH

Call a Control_Click Event when UserForm is Initialized
 
I have a UserForm with several CheckBoxes, TextBoxes, ComboBoxes, etc. I
also have a Command Button Click Event that calculates totals of everything.
I have the Controls in the UserForm autofilled by a worksheet and then call
the Userform. For example:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

''''code to autofill userform

UserForm.Show
End Sub

I want to insert some code to automatically call the commandbutton_click
event so all my totals will automatically be there and the user does not have
to click the command button, how do I do this?

Thanks for your help in advance!!


sebastienm

Call a Control_Click Event when UserForm is Initialized
 
Hi,
I suppose you fill controls in the form in the _Initialize event.
Move this code in a new sub of the Userfomr:
Public Sub FillForm( )
and in _Initialize, just call FillFOrm
Also, move the code that calculates the form out of the _Click event:
Public Sub Calculate()
and in _Click, just call Calculate

Now to show the form:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
USeform.FillForm
Userform.Calculate
UserForm.Show
End Sub


--
Regards,
Sébastien
<http://www.ondemandanalysis.com
<http://www.ready-reports.com


"RyanH" wrote:

I have a UserForm with several CheckBoxes, TextBoxes, ComboBoxes, etc. I
also have a Command Button Click Event that calculates totals of everything.
I have the Controls in the UserForm autofilled by a worksheet and then call
the Userform. For example:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

''''code to autofill userform

UserForm.Show
End Sub

I want to insert some code to automatically call the commandbutton_click
event so all my totals will automatically be there and the user does not have
to click the command button, how do I do this?

Thanks for your help in advance!!



All times are GMT +1. The time now is 01:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com