Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50057

Setting properties on a dynamic userform

$
0
0
Two questions:

I have a userform which contains several (100) checkboxes which a user will use to choose search terms. I set the checkboxes' Caption properties to the values in one of three lookup lists. In VB.net, I'd do the following:

form = New SearchForm ' probably in the commandbutton Click event on the sheet where the user wants to search
form.m_cbx1.Caption = str:Captions(1) 'where strCaptions() is passed in to the form somehow
...
form.m_cbx20.Caption = strCaptions(20)
form.m_cbx21.Hide()
...
form m_cbx100.Hide()
form.Show()

However, this doesn't quite work in VBA. On the form.Show(), I get error 'Object required' on the first line that sets the Caption property. If I move the Show() before the Caption setting, I get error 'Automation error. The callee (server [not server application]) is not available and disappeared; all connections are invalid. The call may have been executed.'.

SECOND, I'd really like to put the checkboxes into an array, like
Dim m_cbx as CheckBox
m_cbx(1) = cbx1
'...etc.

Then I could use a loop, like
For i = 1 To Len(astrChoices)
m_acbx(i).Caption = astrChoices(i)
Next

However, on the highlighted line I get 'Object variable or With block variable not set.'

Can someone tell me how I can do either or both of these things in VBA? Thanks.

Viewing all articles
Browse latest Browse all 50057

Trending Articles