PDA

View Full Version : Solved: userform variable



AJS
10-04-2004, 07:57 PM
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

Jacob Hilderbrand
10-04-2004, 08:05 PM
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

AJS
10-04-2004, 08:11 PM
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.

Jacob Hilderbrand
10-04-2004, 08:50 PM
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

AJS
10-04-2004, 08:56 PM
Thanks for that, it's working fine!

Jacob Hilderbrand
10-04-2004, 09:10 PM
You're Welcome

Take Care