Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a Text Box 2

Status
Not open for further replies.

droberts200401

IS-IT--Management
Mar 29, 2004
13
0
0
GB
Hi,

Is there any way to populate a text box from a selction that a person has made from a combo box? The text box I would ideally like to store in the header of the Word document.

Actions I would like -

1. User makes selection from Combo Box,
2. User fills in the next part of the form,
3. Meanwhile the text box has been populated from the selction thay made from the Combo Box

Reason being is to automate my form a little so the user will not have to do as much work. Any suggestions, thanks in advance

Regards
 
Hi
Just as a hint to get the best answer
I assume this is ....
Access VBA? ->forum705
Access Forms? ->forum702

Anyway, I guess what you need is:
- As "AfterUpdate" event of your combo box, choose "Code"
- adapt the following code with the correct control names:
Code:
Me!textbox=Me!combobox

This should already do the trick.
;-)

Cheers,
Andy

[blue]The last voice we will hear before the world explodes will be that of an expert saying:
"This is technically impossible!" - Sir Peter Ustinov[/blue]
andreas.galambos@bowneglobal.de
HP:
 
Andy:
The text box I would ideally like to store in the header of the Word document.


Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
Right Geoff, now yousay it... - must have worked too long! [blush]
 
Me Again,

Thanks for the help. I can get the result into the Text Box, however If I change the selection I've made in the ComboBox the text box does not update.

The code I have to run the update is such -

Private Sub TextBox1_Change()
TextBox1 = ComboBox1
End Sub

Any ideas, I'm pulling my hair out with VBA as I've only used it for a week albeit with others help ;-)
 
Andy - LOL - we've all been there

droberts200401 - how are you changing the selection ?

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 

This is all of my code -

Code:
Private Sub ComboBox1_List()
ComboBox1.AddItem "Secret"
ComboBox1.AddItem "Classified"
ComboBox1.AddItem "Unclassified"
End Sub

Private Sub ComboBox1_Change()

End Sub

Private Sub Document_Open()
ComboBox1.AddItem "Secret"
ComboBox1.AddItem "Classified"
ComboBox1.AddItem "Unclassified"
End Sub



Private Sub ComboBox1_AfterUpdate()

End Sub

Private Sub TextBox1_Copy()
TextBox1 = ComboBox1
End Sub

Any Ideas where i'm going wrong, once again thanks for your assistance.

Regards

Dave
 
Sorry - should've spotted that 1st time - you need code in the combobox_change event:

Code:
Private Sub ComboBox1_Change()
TextBox1 = ComboBox1
End Sub

You should no longer need the
TextBox1_Copy() sub unless you are using it for something else

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
I take it that this is a UserForm, as you mention "next part" of the form. Or is this using Forms from the forms toolbar?

If it is a VBA userform, why not make a string variable that is equal to the selected item of the combobox? Have it equal the combobox value as part of the OK button (or Done , or whatever) that closes the form. That way, even if the user changes their mind regarding what they select from the combobox, it will always pick up the last one they select. When the form closes use that variable to put in your header.

BTW, if you DO want to have an updating textbox, you should use the ComboBox1_Change event (not the textbox_change event) to update the the textbox. The issue is changing the combobox.

Private Sub ComboBox1_Change()
TextBox1.Text = ComboBox1.Value
End Sub

If you are using a drop down - i.e. from the Forms toolbar - and want to update a textbox from that, make the following the exit macro for the drop down.

Sub UpDateTextBox()
ActiveDocument.FormFields("Text1").Result = _
ActiveDocument.FormFields("DropDown1").Result
End Sub

This simply always makes the value (the Result) of the textbox = the result of dropdown.



Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top