I made the following form.
If i click the "Add Item" button below, the label and text box "Content" will appear.I want to increase the number of button presses.
Sub UserForm_Initialize () Dim adbtn As CommandButton Set Refbtn = .Controls.Add ("Forms.CommandButton.1", "ad", True) With NForm With adbtn'Reflect button .Top = 178 .Left = 20 .Height = 20 .Width = 300 .Caption = "Add item" End With 'Add the following items here With .Controls.Add ("Forms.Label.1", "LEX", True)'Shall .Top = 142'Top position (move display position) .Left = 10'Left position .Height = 20'height .Width = 50'Width .BackColor = 25'Background color .BackStyle = 0 .ForeColor = 1'Text color .Font.Name = "Meiryo"'Text Style .TextAlign = 2'Text position .FontSize = 16'Text size .Caption = "content" End With With .Controls.Add ("Forms.TextBox.1", "TEX", True)'Shanle Label .Top = 132 .Left = 70'Left position .Height = 40'height .Width = 250'width .BorderStyle = fmBorderStyleSingle'Border .BackColor = RGB (255, 255, 255)'Background color .ForeColor = RGB (0, 0, 0)'Text color .Font.Name = "Meiryo"'Text Style .TextAlign = 2'Text position .FontSize = 10'Text size .Text = expa'Display text End With End With End Sub
I have described the items I want to increase in "UserForm_Initialize ()", but I feel that it should be described in the adbtn event.
Even if it is described in the procedure of the event of adbtn, it will increase just by pressing the button, so it will not work?
There is also the question.
The variable in the text box is currently expa, but I want to make the added items different variables, and I want to write them in the cell with the "Reflect" button on the upper left.
I would appreciate any advice.
I look forward to working with you.
~ Addition ~
I added the following event procedure, but nothing happens.
I tried various things such as adding Public and changing adbtn_Click () to ad_Click () (module name), but I could not make it react even if I pressed the button.
I would appreciate any advice on the cause.
Public Sub adbtn_Click () With NForm With .Controls.Add ("Forms.Label.1", "LEX", True)' .Top = 202'Top position (move display position) .Left = 10'Left position .Height = 20'height .Width = 50'Width .BackColor = 25'Background color .BackStyle = 0 .ForeColor = 1'Text color .Font.Name = "Meiryo"'Text Style .TextAlign = 2'Text position .FontSize = 16'Text size .Caption = "content" End With With .Controls.Add ("Forms.TextBox.1", "TEX", True)'Shanle Label .Top = 202 .Left = 70'Left position .Height = 20'height .Width = 250'width .BorderStyle = fmBorderStyleSingle'Border .BackColor = RGB (255, 255, 255)'Background color .ForeColor = RGB (0, 0, 0)'Text color .Font.Name = "Meiryo"'Text Style .TextAlign = 2'Text position .FontSize = 10'Text size .Text = "test"'display text End With End With End Sub
Answer # 1
Since we are adding a text box when we click the command button, we are writing code to add the text box to the event procedure when the command button is clicked.
Instead of adding the add button with UserForm_Initialize (), if you place it on the user form from the beginning, just double-clicking it will add a template of the event procedure at the time of clicking, so add a text box there You just have to write the code to do it.
To refer to the added text box, make the name regular (for example, Txt1, Txt2, txt3 ...) so that you can refer to it by name.
Or you can store it in a dynamic array or collection.
If you're not sure about the above explanation, place the maximum number of textboxes you can expect from the beginning, hide them (Visible = False), and show them when you click adbtn (Visible = True). I think it's easy to understand how to make it work.
- vba - register the control to the command button with userform_initialize
- vba - i want to store the control of the command button in the class
- (vba) i want to make sure that when i press a button for each row, the data in that row is posted to ie
- ie operation by vba (press button)
- html - button operation in ie control with vba
- the process is interrupted when i click the button on the web page with vba
- css - i want to change the color when i press a button in the drawer menu
- in vba, i want to change the path name to be acquired with the button
- html - when i press the submit button, the following error appears
- xcode - i want to be able to press a button and select a different mp3 file to play
- about not being able to press the button you want to press with python scraping
- the result of the operation when pressing the vba button and the input of the play button are different
- even if you press the send button, it will not connect to the php file
- vba - i want to know the xpath of the execute button
- java - i want to change the color when i press the like button and keep the color changed
- vba - i want to show/hide the libreoffice calc button with a macro
- when you press the vbnet button, the display of the character string in the text box is displayed in msgbox
- python (tkinter) i want to open the dialog not only in the button press event but also in the menu selection event, but why is i
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory