CP212 Lab 7 : Userforms

Week of

Practice

The image shown below has had a few other changes made to it, but you can create your form however you want.

Sample Login Userform


Instructions


Lab Tasks

  1. Create the userform shown below:
  2. main_form (8K)

    • The form should contain a the usual OK and Cancel buttons.
    • The form also contains a list box whic allows the user to select only one item from the list.
    • Write a sub Populate that populates the list with the provinces Alberta, British Columbia, Manitoba, New Brunswick, Newfoundland and Labrador, Nova Scotia, Ontario, Prince Edward Island, Quebec, and Saskatchewan in thie same order. Select Ontario as default.
    • Write a code in a module ShowForm so that the user sees the form. The user either select an item from the list or clicks Cancel. When a province is selected from the list as shown below:
    • main_form (8K)

      , and then clicks OK, the user should see a message as,"You live in Ontario"

      main_form (8K)

    • While when the Cancel or X button is clicked, the message "You must not live in a Big Ten Provinces" should appear:

      main_form (8K)

    • Your excel worksheet should have a button to run a module and access the user form. Based on the user form, user either selects a province then a message showing a province , or selects, Cancel or X the response will show a message of "You must not live in a Big Ten Provinces"
    • When the user tries to close the form by clicking the upper right X, the following sub can be used

      Private Sub UserForm_QueryClose(cancel As Integer, CloseMode As Integer)
          If CloseMode = vbFormControlMenu Then cmdCancel_Click
      End Sub
      
  3. Create the userform shown below:

    calculate_Sum (21K)
  4. This form contains a frame, labels, a RefEdit control, two buttons, and a scrollbar. When you click the Sum button, it should display a message box indicating the Sum of the selected cells.

    Note: The RefEdit control has a Value property which returns a string containing the address of the selected range. To create a range object from this address use a line like:

    Dim range1 As Range
    
    set range1 = Range(refEdit.Value)
    

    When you click the Cancel button, the form should close/unload. Use the Accelerator property for each button to include the HotKey (displays the underscore and allows that key to execute the button when pressing Alt.)

    To activate the scrollbar, you need to access and modify its properties such as ScrollTop and ScrollHeight. Please note that scrollbar can be activated by assigning appropriate value to the ScrollBars property of the form.

Note

  • You have to use Button(s) on worksheet to run the tasks in this lab and all next labs and assignments. Marks will be deducted if you do not use Buttons

  • You can use only the covered material in the course till now. You can't use uncovered topics. You can't use topics out of the context of this course.