Share this Page URL

UserForms > UserForms - Pg. 440

Initialize The Initialize event of the form, which fires when the form is opened, is useful for filling in default values for controls on the form. Click The Click event of many controls (most commonly used with a command but- ton), which fires when the user clicks the control, can be used to run code. Typically UserForms have an OK button with code that performs an action, often using values set from other controls on the form. Change The Change event of a text box control, which fires when the text in the control is changed, can be used to respond to a change made by a user. A UserForm is often popped up from code on the Document_New or Document_Open event of a template, so that the user will be presented with the form when a document is opened, or a new document is created from a template. The UserForms could also be popped up from Word macros (event procedures) placed as buttons on the tool- bar. The code in Example 18-40 uses the Document_New event to give the user a choice of working with data from Access or Outlook. Example 18-40. Opening a User Form with a New Document Private Sub Document_New( On Error GoTo ErrorHandler )