having trouble adding more than one textbox to a form using vba

  • Thread starter Thread starter GregJG
  • Start date Start date
G

GregJG

I am having problems with the following code. I can get 1 textbo
created with the correct value, as long as only 1 checkbox is true. bu
if they both are true, only one textbox is created and no value.

can anyone see what I am doing wrong or help to improve code?


Set wb = Workbooks.Open("PATH")
If MultiPage1.Pages(0).Checkbox1.Value = True Then
Set NewTextBox = MultiPage1.Pages(1).Add("forms.textbox.1")
With NewTextBox
.Width = 150
.Height = 18
End With
Set rng
wb.Worksheets("Sheet1").Columns(1).find(MultiPage1.Pages(0).Checkbox1.Caption)

If Not rng Is Nothing Then
MultiPage1.Pages(1).TextBox1 = rng.Offset(0, 1)
End If
End If

If MultiPage1.Pages(0).checkbox2.Value = True Then
Set NewTextBox = MultiPage1.Pages(1).Add("forms.textbox.1")
With NewTextBox
.Width = 150
.Height = 18
End With
Set rng
wb.Worksheets("sheet1").Columns(1).find(MultiPage1.Pages(0).checkbox2.Caption)

If Not rng Is Nothing Then
MultiPage1.Pages(1).TextBox2 = rng.Offset(0, 1)
End If
End I
 
This isn't an answer to your question, but you may find it easier just adding
the textbox controls to your form while you're creating it.

Then just toggle the visibility depending on what your checkboxes. (And add the
text, too.)
 
Dave,

thanks for your response. The form is being created "dynamically" (
think that is the term).


Private Sub CommandButton1_Click()

Dim myObj As Object
Dim NewTextBox As MSForms.textbox
Dim NewButton As MSForms.CommandButton
Dim NewLabel As MSForms.Label
Dim rng As Range

With MultiPage1
Set myObj = .Pages.Add("Proposal")
With myObj
End With
End Wit
 
I think you're actually putting the second one right on top of the first one.

'adding the first one...
With NewTextBox
.Top = 0
.Width = 150
.Height = 18
End With

'adding the second one....
With NewTextBox
.Top = 33
.Width = 150
.Height = 18
End With

======
But maybe you could design your Proposoal page upfront. Then hide it, too.
Only show it if it's required.

Private Sub UserForm_Initialize()
Me.MultiPage1.Pages("proposal").Visible = False
End Sub

Then when you need it later, just unhide it.
 
you were exactly right dave. thanks alot!

But now i have discovered that there will be a design flaw in printin
the form when I am done. I think I will need to create one large
textbox and add text to it. there MIGHT be up to 26 lines with
seperate text on each line. and when I print, I only want the on
textbox to print.

i.e.

this is line one including the dashes--------------------then it'
match
this is line two-----------------------------------------------the
it's match
this is line three---------------------------------------------the
it's match
ect...

printing the form with seperate text boxes won't look right.

creating one large textbox with multiline true should do the trick
Then only print what is in the textbox.

what do you think
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top