ddalenberg
08-13-2010, 06:17 AM
I apologize if this a topic that has already been addressed, I have been looking for solution for a couple days and haven't found anything.
I am creating a document that has one combobox and several textboxes that are controlled by the selection a user makes in said combobox.
The user will choose between 2 part numbers, and then using textboxes that I have inserted manually, the chosen part number wil be displayed on each page. Example of what I have so far:
Private Sub Document1_Open()
ComboBox1.List = Array("Choose a Part #", _
"Part #1", _
"Part #2")
ComboBox1.ListIndex = 0
End Sub
Private Sub ComboBox1_Change()
' TextBox 1 Page 1
If ComboBox1 = "Choose a Part #" Then TextBox1 = Blank
If ComboBox1 = "Part #1" Then TextBox1 = "Part #1"
If ComboBox1 = "Part #2" Then TextBox1 = "Part #2"
End Sub
This works well, and does what I want it to do, but I have a 26 page document, and will have 26 textboxes in which the part number must be displayed.
I am very new to VBA and have no idea how to clean this up. Rather than write the ComboBox1_Change() code 26 times, I would like to create some sort of array for the textboxes, and then run a For loop of sorts for my If conditional statement, to display my part number.
Any idea how to make this happen?
Thanks!
I am creating a document that has one combobox and several textboxes that are controlled by the selection a user makes in said combobox.
The user will choose between 2 part numbers, and then using textboxes that I have inserted manually, the chosen part number wil be displayed on each page. Example of what I have so far:
Private Sub Document1_Open()
ComboBox1.List = Array("Choose a Part #", _
"Part #1", _
"Part #2")
ComboBox1.ListIndex = 0
End Sub
Private Sub ComboBox1_Change()
' TextBox 1 Page 1
If ComboBox1 = "Choose a Part #" Then TextBox1 = Blank
If ComboBox1 = "Part #1" Then TextBox1 = "Part #1"
If ComboBox1 = "Part #2" Then TextBox1 = "Part #2"
End Sub
This works well, and does what I want it to do, but I have a 26 page document, and will have 26 textboxes in which the part number must be displayed.
I am very new to VBA and have no idea how to clean this up. Rather than write the ComboBox1_Change() code 26 times, I would like to create some sort of array for the textboxes, and then run a For loop of sorts for my If conditional statement, to display my part number.
Any idea how to make this happen?
Thanks!