问题
I am trying to create a userform. After I select the product code and enter the quantity, I want this code to appear in the frame as many as the number entered, and I want a TextBox to be created for entering the expiration date. You can see what ı am aiming at the pictures.
This is the main structure of my user form. It must look like this after adding the product code and quantity.
回答1:
Your goal is ambitious and isn't simple at all. I can give you some hints but you will have to complete it.
So to answer your original question, you can define controls in a frame this way:
Dim tb as Object, lb as Object
Set tb = Frame1.Controls.Add("forms.textbox.1")
Set lb = Frame1.Controls.Add("forms.label.1")
lb.caption = <the recently entered product code>
lb.top = <you need to keep track of position of next entry>
lb.left = 50 ' from the left border of frame1
tb.top = lb.top
tb.left = lb.left + 100
Then you have to store the textboxes in a collection (or array, as you wish) to process the expiration dates entered.
Shortly and quickly. Please note that you will have to implement many more functions to make your app robust and reliable.
回答2:
You description doesn't make a lot of sense but to answer your
Question:
How to add text boxes and labels to a frame within a userform?
Draw the frame first.
Draw the controls "on top" of the frame.
You can confirm the control is attached to the frame by clicking elsewhere,then clicking the control, and verifying that the frame is automatically selected as well.
来源:https://stackoverflow.com/questions/49550026/how-to-add-text-boxes-and-labels-to-a-frame-within-a-userform