Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default proper way to create a userform

Hi all,

just wondering what the 'correct' way to initialize and dispose of a
userform is.

presently i am doing something like this:

private sub UserForm_Initialize()
' clear contents of combo boxes, label captions, etc
' set up initial values of the above
end sub

public sub init(optional arg as variant)
UserForm_Initialize
'any other code to run here / sub calls
MyForm.show
end sub

private sub myButton_clicked()
MyForm.hide
end sub

and externally (from another module)

MyForm.init()


is there a better (more correct) way to do this?

tia

J
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default proper way to create a userform

j,

A userform goes thru two steps...
1. It is loaded into memory - the Initialize event takes place during loading.
2. It is shown to the user - the Activate event takes place here.

Step 1 (loading) takes place only once and occurs whenever the userform is
referenced in code. So a statement like UserForm1.Width = 500 automatically
loads the form.
Step 2 (showing the form) can take place as many times as you require.
The Activate event will occur each time the form is shown. (UserForm1.Show)
Obviously, the form must be hidden (UserForm1.Hide) each time
before it can be shown again.

It is not necessary to write code to specifically load a userform as
UserForm1.Show will load the form and show it.

The usual procedure (at the programming desk here) is to place any
one time code in the Initialize event in the userform code module.
Any code you want to run each time the form is shown is
placed in the Activate event in the userform code module.
The code for the above would be entered in the form module during
design of the userform and would not have to be referenced again.

The general code module code that initiates the process could be as simple as...
'--------------------------------
Sub GetThingsGoing
Dim strUserInput as String
'Do normal checks for protected workbooks etc.

UserForm1.Show

'(The "close" button on the form should hide the form)

'Get information entered into userform...
strUserInput = UserForm1.TextBox1.Value

'After getting info, release memory required for the form.
Unload UserForm1
Set UserForm1 = Nothing

'Other code here to do something with the string variable.
End Sub
'--------------------------------
Jim Cone
San Francisco, USA


"Gixxer_J_97"
wrote in message
...
Hi all,
just wondering what the 'correct' way to initialize and dispose of a
userform is.
presently i am doing something like this:
private sub UserForm_Initialize()
' clear contents of combo boxes, label captions, etc
' set up initial values of the above
end sub

public sub init(optional arg as variant)
UserForm_Initialize
'any other code to run here / sub calls
MyForm.show
end sub

private sub myButton_clicked()
MyForm.hide
end sub

and externally (from another module)
MyForm.init()

is there a better (more correct) way to do this?
tia
J
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
Create UserForm programmatically Ber Excel Programming 5 September 11th 05 11:20 AM
dynamically create userform Janelle Excel Programming 7 December 17th 04 04:47 PM
userform create masterphilch Excel Programming 1 October 25th 04 08:07 PM
How to create a dynamic Userform via VBA SuperJas Excel Programming 1 December 12th 03 02:51 AM
Create and show UserForm from Add-In Rick Knight[_2_] Excel Programming 3 December 9th 03 01:04 AM


All times are GMT +1. The time now is 10:20 AM.

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

About Us

"It's about Microsoft Excel"