Set a combo box to an entry and clear it of everything

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using Office 2003 and Windows XP; using VBA, how can I:

1) Programmatically set a combo box to a particular entry in the drop down
list?

2) Clear the combo box drop down list of all entries?

If possible, please post generic VBA example code.

Thanks a lot in advance.
 
XP said:
Using Office 2003 and Windows XP; using VBA, how can I:

1) Programmatically set a combo box to a particular entry in the drop down
list?

Me!ComboBoxName = SomeValue

SomeValue would need quotes around it if it was a Text value.
2) Clear the combo box drop down list of all entries?

Don't understand what you mean by "entries". A ComboBox can have only one
"selection" so I must assume you want all of the choices in the list removed?
In that case just set the RowSource property to "".

Me!ComboBoxName.RowSource = ""
 
Hi and thanks Rick.

When I run this code from a standard code module:

Forms(gcsFormMainMenu).Controls("cboMainDept1") = 0

It sets the value of the drop down to zero rather than the first item in the
drop down list. How can I make that work?

Thanks again.
 
XP said:
Hi and thanks Rick.

When I run this code from a standard code module:

Forms(gcsFormMainMenu).Controls("cboMainDept1") = 0

It sets the value of the drop down to zero rather than the first item in the
drop down list. How can I make that work?

Well, that is not what you asked for :-)

If the bound column of the ComboBox is the first one...

Forms(gcsFormMainMenu).Controls("cboMainDept1") =
Forms(gcsFormMainMenu).Controls("cboMainDept1").Column(0,0)

If the bound column is not the first column then the first zero would be changed
to 1 for the second column, 2 for the third, etc.. The second zero would not be
changed as that specifies the first row.
 
Rick Brandt said:
Well, that is not what you asked for :-)

YEAH, I know; things changed as I was developing. This is sort of a follow
up...
If the bound column of the ComboBox is the first one...

Forms(gcsFormMainMenu).Controls("cboMainDept1") =
Forms(gcsFormMainMenu).Controls("cboMainDept1").Column(0,0)

If the bound column is not the first column then the first zero would be changed
to 1 for the second column, 2 for the third, etc.. The second zero would not be
changed as that specifies the first row.

WORKS great thanks!
 

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