comcu Posted August 29, 2008 Share Posted August 29, 2008 Hi, I hope someone can help. I am trying to add a command button to a form. This button, when pressed will display an unlimited number (with in reason) of text boxes ,called TBxInt ready for the users input. The qty of the text box ‘TBxInt ‘ depends on the value held by another text box, called TBxVal. For eg if TBxVal.value = “9” then create TBxInpt(0-9) TBxInpt.width = 8 TBxInpt(0).left = 0 TBxInpt(1).left = 10 TBxInpt(2).left = 20 Etc etc The user can then input values into each text box and the values will be used for further calculations. If anyone knows of any example or tutorials on this I would appreciate it Many thanks, col Quote Link to comment Share on other sites More sharing options...
rocheey Posted August 30, 2008 Share Posted August 30, 2008 In VB, this would be called a "Control Array", and its built in. But in VBA, since we dont have Control Arrays, we'll make our own Array of Controls. ' in a blank VBA userform, drop in the following code, run the form, 'and click the form to have it create the controls on the fly. ' ---- snip -------- snip -------- snip -------- snip ---- Dim cmdButton() As MSForms.CommandButton Private Sub UserForm_Click() Dim numButtons As Integer: numButtons = 4 ReDim cmdButton(numButtons) Dim I As Integer For I = 0 To numButtons ' create a control on the fly Set cmdButton(I) = Me.Controls.Add("Forms.CommandButton.1", "Command" & LTrim$(Str$(I)), True) ' set its position and size cmdButton(I).Height = 20: cmdButton(I).Width = 100 cmdButton(I).Left = 5: cmdButton(I).Top = (I * 25) + 5 cmdButton(I).Caption = "Command " & I Next I ' resize the form around the text boxes Me.Width = 115 Me.Height = ((numButtons + 2) * 25) End Sub ' ---- snip -------- snip -------- snip -------- snip ---- Quote Link to comment Share on other sites More sharing options...
comcu Posted August 30, 2008 Author Share Posted August 30, 2008 rocheey, thank you i will give it a go! cheers, col Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.