Consulting

Results 1 to 6 of 6

Thread: Userform variable

  1. #1
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location

    Userform variable

    Hi,

    What's wrong with the following code? I'm trying to load up and format a userform based on the selection in a listbox, but I get an "object doesn't support this property or method" error message at the "SetForm.Show vbModeless" line.

    Thanks, Aaron.

    Private Sub OKButton1_Click()
    ' load a userform
    Dim SetForm As UserForm
    If ToolList.ListIndex < 0 Then ToolList.ListIndex = 0
    If StrComp(ToolList.Value, "Vernier Calipers", 1) = 0 Then
    Set SetForm = GaugeLink_Measurement
    ElseIf StrComp(ToolList.Value, "Pass/Fail", 1) = 0 Then
    Set SetForm = PassFail_Measurement
    Else
    Set SetForm = VisionGauge_Measurement
    End If
    SetForm.Show vbModeless
    ' rest of code...
    end sub

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Private Sub OKButton1_Click()
    If ToolList.ListIndex < 0 Then ToolList.ListIndex = 0
        If StrComp(ToolList.Value, "Vernier Calipers", 1) = 0 Then
            GaugeLink_Measurement.Show
        ElseIf StrComp(ToolList.Value, "Pass/Fail", 1) = 0 Then
            PassFail_Measurement.Show
        Else
            VisionGauge_Measurement.Show
        End If
    End Sub

  3. #3
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Sorry, won't work for my purposes. After calling up the userform I have to populate some listboxes (I should have included that in the original code!) via:

    For i = 1 To Sheet1.Range("C8").Value
        If Sheet1.Cells(7 + i, 7) = ToolList.Value Then
            SetForm.DimList.AddItem Sheet1.Cells(7 + i, 6)
        End If
    Next i
    which is why I want to use a userform variable.

    Thanks, Aaron.

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try this:


    Option Explicit
    
    Private Sub OKButton1_Click()
    ' load a userform
    Dim SetForm As String
    If ToolList.ListIndex < 0 Then ToolList.ListIndex = 0
        If StrComp(ToolList.Value, "Vernier Calipers", 1) = 0 Then
            SetForm = "GaugeLink_Measurement"
        ElseIf StrComp(ToolList.Value, "Pass/Fail", 1) = 0 Then
            Set SetForm = PassFail_Measurement
        Else
            Set SetForm = VisionGauge_Measurement
        End If
        VBA.UserForms.Add(SetForm).Show
    ' rest of code...
    End Sub

  5. #5
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Thanks for that, it's working fine!

  6. #6
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

Posting Permissions

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