0

I'm sure I'm being a bit thick here but can't for the life of me see why this run-time error is occurring. Here's the code:

Public Sub fRTWIni()

Dim varList As Variant
Dim intR As Integer
Dim con As Control

varList = fGetList("ct_adt_RTWYesNo", "ORDER BY RTWYesNo ASC")

For Each con In UF_ReturnToWork.frmRTW.Controls
    If TypeName(con) = "ComboBox" And con.Name <> "cbRTWHH" And con.Name <> "cbRTWMM" Then
        con.ColumnCount = 2
        con.ColumnWidth = 0
        For intR = LBound(varList, 2) To UBound(varList, 2)
            con.AddItem intR
            con.Column(1, intR) = varList(1, intR)
        Next intR
    End If
Next con

End Sub

The error is occurring on line:

For Each con In UF_ReturnToWork.frmRTW.Controls

UF_ReturnToWork is a userform. frmRTW is a frame.

I've used this method plenty of times to access the controls with a userform / frame and am absolutely stumped as to why I can't use is now.

As far as I'm aware and from my research, .Controls is a member of the object and therefore I can't understand why it wont allow me to use it.

Any ideas why the error is occurring?

Thanks Gareth

2
  • Place UF_ReturnToWork.frmRTW.Controls in the watch window to see if it returns a collection of controls, as you'd expect. Commented Mar 17, 2014 at 15:22
  • @shahkalpesh it returns <Object variable or With block variable not set>. Thanks Commented Mar 17, 2014 at 15:30

1 Answer 1

1

The error is in:

con.ColumnWidth = 0

should be

con.ColumnWidths = 0
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much! I looked at it for far too long to spot that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.