stone_house
New Member
- Joined
- Jun 3, 2015
- Messages
- 2
Hello,
This is my first post, so I apologize in advance if the format or content is irregular.
I created a Userform in designer mode, inside which controls need to be added or deleted as necessary. The reason is due to the highly variable amount of data that may need to be entered (it could be as few as 1, or as many as 60). I have so far been successful in dynamically adding controls, and providing them with names, etc., but then I'm entirely unsure as to how to reference those newly added controls.
I even checked the object browser, under my UserForm, and none of the controls that were added in run-time were listed there.
So I guess my question is two-fold: where are these objects stored? How do I reference them? Following is a greatly simplified version of what I'm trying to do:
In every case I get a Run-time error saying "Could not find the specified object."
Any help would be greatly appreciated.
Thanks,
Aaron
This is my first post, so I apologize in advance if the format or content is irregular.
I created a Userform in designer mode, inside which controls need to be added or deleted as necessary. The reason is due to the highly variable amount of data that may need to be entered (it could be as few as 1, or as many as 60). I have so far been successful in dynamically adding controls, and providing them with names, etc., but then I'm entirely unsure as to how to reference those newly added controls.
I even checked the object browser, under my UserForm, and none of the controls that were added in run-time were listed there.
So I guess my question is two-fold: where are these objects stored? How do I reference them? Following is a greatly simplified version of what I'm trying to do:
Code:
'This is code used to add the control, which is initiated by SpinUp of a SpinButton
Private Sub Chg_Entry_SpinUp()
Dim TopHeight As Long
TopHeight = 240 + (Val(Chg_Entry.Value) - 1) * 54
With Me.Controls.Add("Forms.TextBox.1", "NewEntry")
.Height = 18
.Left = 18
.Top = TopHeight
.Width = 90
End With
'That works just fine; however, when I try to remove "NewEntry", for instance, I run into problems. This is what I tried, with the SpinDown of the same SpinButton:
Private Sub Chg_Entry_SpinDown()
Me.Controls.Remove ("NewEntry")
End Sub
'I've tried referencing "NewEntry" in a number of different syntaxes, to no avail; including:
'Me.Controls("NewEntry")
'Me!NewEntry
'Me![NewEntry]
'Me("NewEntry")
In every case I get a Run-time error saying "Could not find the specified object."
Any help would be greatly appreciated.
Thanks,
Aaron
Last edited: