Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic control arrays (arrays of visual objects) 5

Status
Not open for further replies.

krinid

Programmer
Jun 10, 2003
356
CA
Does anyone know how to create control arrays?
I'm interested in creating these at both design and run-time. It's easy enough in VB, but I haven't found a way to do it in VBA yet. In particular, I'm trying to create an array of buttons, checkboxes and radio buttons.
 
Hi,
maybe this will be useful in the project, still with UserForm1 as a template, but with an instance created within the class and some properties added:

a class clsF:
Code:
Public WithEvents frm As MSForms.UserForm

Private m_Form As UserForm1

Private Sub Class_Initialize()
Set m_Form = New UserForm1
Set frm = m_Form
End Sub

Private Sub Class_Terminate()
Set m_Form = Nothing
End Sub

Public Sub fShow()
m_Form.Show vbModeless
End Sub

Private Sub frm_Click()
MsgBox "custom form " & Me.fCaption & " clicked"
End Sub

Public Property Get fWidth() As Double
fWidth = m_Form.Width
End Property

Public Property Let fWidth(ByVal vNewWidth As Double)
m_Form.Width = vNewWidth
End Property

Public Property Get fCaption() As String
fCaption = m_Form.Caption
End Property

Public Property Let fCaption(ByVal vNewCaption As String)
m_Form.Caption = vNewCaption
End Property

a standard module:
Code:
Dim x As clsF, y As clsF

Sub Show2Forms()
Set x = New clsF
Set y = New clsF
x.fCaption = "custom form 1 caption"
x.fWidth = 400
y.fCaption = "custom form 2 caption"
y.fWidth = 200

x.fShow
y.fShow
End Sub

combo
 
I see what my problem was...
Private m_Form As UserForm1

causes no problems, it's just

Public WithEvents frm As UserForm1

that was generating the automation error. I'll implement that tomorrow - cheers once more combo! You've earned 10 stars for your help on this as far as I'm concerned.
 
One last kick at the can . . .

I've got this up, working and running now... BUT, is there anyway catch the "Activate" method of a dynamic form? While static forms have an Activate method, it seems dynamic ones don't. :(

My purpose:
I've put minimize/maximize buttons on my dynamic form (I can put up the code if necessary - API calls) and to keep these buttons on the form, some code needs to be run when the form becomes active. Otherwise the buttons disappear. The danger of this is of course that once you minimize the form, work on something else, next time you click the form (to maximize it or restore it, perhaps) the min/max buttons disappear, stranding the form in minimize mode.

One last strange item of info:
Static forms don't seem to require this constant reapplication of the min/max buttons. It's just the dynamic ones. Even stranger, clicking on the worksheet, then again clicking the dynamic form shows this symptom of the min/max buttons disappearing when it becomes active. However, after the min/max buttons have disappeared from the dynamic form, I click on a static form (even one without min/max buttons), then click on the dynamic form again, the buttons come back on the dynamic form. Strange things are afoot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top