Results 1 to 5 of 5

Thread: Referencing a Userform in a module

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jan 2014
    Posts
    2
    Location

    Question Referencing a Userform in a module

    Hi Vbax users

    I'm creating a number of userforms and at the top of these forms I am adding a combo box and a spin button.

    The function of these controls does the same thing on each form so I'm trying to create a Public Sub in a module which will create these controls.
    But I am getting a Type-Mismatch error.

    These test I've done so far is as follow:

    Code in Module1:

    Public Sub SiteSelector(CurrentForm as Userform)
    Dim TestCombo as MSForms.ComboBox
    Set TestCombo = CurrentForm.Controls.Add("Forms.ComboBox.1", "TestCombo", True)
    End Sub
    Code in form(I applied it to a button click event):

    Private Sub CommandButton1_Click
    Module1.SiteSelector(Me)
    End Sub
    Thanks in advance
    Last edited by SamT; 01-07-2014 at 10:53 AM. Reason: Added Code Tags with Post Editor # Icon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •