Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.
in the code module of the UserForm (DatePicker - no relation of the Excel form by the same name)
Public WithEvents CalBtn As MSForms.Label Public pParent As DatePicker Public Property Get Parent() As DatePicker Set CalForm = pParent End Property Public Property Set CalForm(CalForm As DatePicker) Set pParent = CalForm End Property Private Sub CalBtn_Click() MsgBox CalBtn.Name & " was clicked." Debug.Print CalBtn.Parent.Name ' DOESN'T WORK End Sub
The code runs and works without the Parent property idea. What am I doing wrong, and how to do it right?
Dim Btn() As CalButton Private Sub AssignCalButtons() ' assign all day button to CalButton class Dim Ctl As Object Dim i As Long ReDim Btn(1 To Me.Controls.Count) For Each Ctl In Me.Controls If InStr(1, Ctl.Name, "Day", vbTextCompare) = 1 Then i = i + 1 Set Btn(i) = New CalButton Set Btn(i).CalBtn = Ctl Set Btn(i).Parent = Me ' Compile error: Invalid use of property End If Next Ctl ReDim Preserve Btn(1 To i) End Sub
Join the community of 500,000 technology professionals and ask your questions.