Calling Button click event from Form initialise event?

N

noname

Hi,

I have a form with multipage containing 4 pages. Each page has frame
with controls like textboxes and comboboxes on it.

By clicking the Red X on title bar, i hide the form and load a
messagebox with Yes, No & Cancel buttons. If Cancel is chosen, the
hidden userform is made visible. But here's the catch, i need to open
the same page i was on, at the time of form hiding. Since on every
page, i have a button that has code which opens and initializes
controls on the next page, i need to know, can i call the button code
from the form initialize event, using an IF condition like this:

Userform_Initialize()
........
........
If p = 0 Then

'normal form initialization code....

ElseIf p = 1 Then

Call eqForm.cmd_AddBrands_Click

ElseIf p = 2 Then

Call eqForm.cmd_AddFactors01_Click

ElseIf p = 3 Then

Call eqForm.cmd_AddFactors02_Click

End If

End Sub


Anybody has ideas how to do this, instead of copy- pasting the
individual button_Click codes again into the form initialize event.
 
M

Mike S

Hi,

I have a form with multipage containing 4 pages. Each page has frame
with controls like textboxes and comboboxes on it.

By clicking the Red X on title bar, i hide the form and load a
messagebox with Yes, No& Cancel buttons. If Cancel is chosen, the
hidden userform is made visible. But here's the catch, i need to open
the same page i was on, at the time of form hiding. Since on every
page, i have a button that has code which opens and initializes
controls on the next page, i need to know, can i call the button code
from the form initialize event, using an IF condition like this:

Userform_Initialize()
.......
.......
If p = 0 Then
'normal form initialization code....
ElseIf p = 1 Then
Call eqForm.cmd_AddBrands_Click
ElseIf p = 2 Then
Call eqForm.cmd_AddFactors01_Click
ElseIf p = 3 Then
Call eqForm.cmd_AddFactors02_Click
End If
End Sub
Anybody has ideas how to do this, instead of copy- pasting the
individual button_Click codes again into the form initialize event.

Try this:

If p = 0 Then
'normal form initialization code....
ElseIf p = 1 Then
eqForm.cmd_AddBrands.Value = True
ElseIf p = 2 Then
eqForm.cmd_AddFactors01.Value = True
ElseIf p = 3 Then
eqForm.cmd_AddFactors02.Value = True
End If
 
N

noname

Try this:

If p = 0 Then
     'normal form initialization code....
ElseIf p = 1 Then
     eqForm.cmd_AddBrands.Value = True
ElseIf p = 2 Then
     eqForm.cmd_AddFactors01.Value = True
ElseIf p = 3 Then
     eqForm.cmd_AddFactors02.Value = True
End If

Thanks Mike,

You are fantabulous :)

This works!!!
 

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