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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEW to VBA

Status
Not open for further replies.

droberts200401

IS-IT--Management
Mar 29, 2004
13
GB
Help, as the subject says it all!

Would like a drop down box that has three options, this is my code -

Private Sub ComboBox1_Change()
ComboBox1.AddItem "A"
ComboBox1.AddItem "B"
ComboBox1.AddItem "C"
End Sub

However when a user selects one of the dropdown options (in a ComboBox) and has clicked out of the combo box, if they were to change their mind on the option they have selected the three fields have repeated themselves in the combobox. Any ideas please :)
 
droberts200401,

You need to LOAD the values into your Combobox in a DIFFERENT procedure -- NOT the Change event.

I would use the Click event whenever the user selects a value in the Combobox.

What do you want to happen when the user makes such a selection???

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
droberts,
The additem method is used to add rows to a pre-existing list (just like what is happening to you), so every time you have a change event you add a whole new set of values.

What you probably want to do is to:
Open your form in design view.
Right click on the combo box.
Select "Properties".
Click the "Data" tab.
Change the "Row Source Type" to "Value List".
In the "Row Source" box, enter: "A";"B";"C"

If you are needing to add the initial rows, "on the fly", just check the ListCount property of your combo box before you add new items, to make sure you are not adding them to a pre-populated list.

Hang in there--it gets easier after a while. Write back if you continue to have problems.

Tranman
 
SkipVought, thanks for the speedy reply, I have tried the Click event however when I use this event none of the combobox options appear, this is true of other events I have tried and failed with.

When the user makes their selection I just want the value to stay in the box so when they print out the document the option they have selected prints out on the document.

Regards
 
What application are you woking in? What kind of combobox are you using?

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
TranMan - Sorry if I'm being completely ignorant, I'm using Word 97 and accessed VB that way and I can't see the 'Row Source Type' in properties.

SkipVought - Im just using a ComboBox from the Tools menu in Word 97.

Really sorry guys for being a VB newbie and thanks for advice you have suggested thus far

Regards
 
There are Form Toolbar or COntrol Toolbox comboboxes???

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
SkipVought

Its a Control Toolbox combobox.

Have tried to get around the whole VB issue with Form Toolbar, I need to lock the document so users would not change any of the form content, however this also locks the header which the user needs to change and so is not an option for me to use.

Regards
 
I don't know how your document operates, but...

1. in the Document_Open event, load the combobox using the AddItem method.

2. what combobox options are you looking for when the user makes a selection? there are none! it's just a selection.

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
We need a bit more clarity to be able to help better. You state that the user will also need to to be able to change the headers. This seems odd to me, but it certainly can be done.

You need to determine your needs precisely. For example you state you want some items in a drop down, and you want the selected item to show up when printed. You also state a problem with using the Forms Toolbar and locking the document. Again, this is not hard to deal with.

Populate the Forms drop down with the items. Put a continous break immediate before, and immediately after the drop down. Lock (protect) only that section.

If the item selected from the drop down IS what you want to change in the header, put an exit macro to the drop down that unprotects the doc, changes header, reprotects automatically. If the drop down selection is NOT what may be changed in the header, then you need another macro that will get the changes and does the header.

Do they always change headers? Seldom? Are there more than one drop down? Is the item selected in the drop down, what will be changed in the header? I know VBA can seem daunting at first, but you will get it I am sure. It is fun and a great tool to truly get a intimate knowledge of what is going on. This is a great forum and we all like to help. So if you post a bit more specifics on what you need to happen, perhaps we can help more specifically.

Hope this helps


Gerry
 
Skip,

Thank you so much for your last reply, with your assistance I have managed to get it working.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top