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!

Stupid ComboBox

Status
Not open for further replies.

FunnyGuy

Technical User
May 26, 2003
19
CA
Hi there,

I am trying to clear a combobox that I have loaded at the beginning of my form. My combo box consists of various items from a table. I am able to load my info into the combo box, no problem.
When the user clicks on a button, I am trying to clear the combo box, but for some reason I cannot clear the damn box!
If I am doing this wrong, please let me know or if you have any advice, any would be appriciated.

'code that starts in the form load event

If IsNull(txtC1) = True Then
Else
cmbContactNames.AddItem txtC1
End If

If IsNull(txtC2) = True Then
Else
cmbContactNames.AddItem txtC2
End If

If IsNull(txtC3) = True Then
Else
cmbContactNames.AddItem txtC3
End If

'Now on my click button event I thought I could do this

cmbContactNames.Clear

Any ideas?

Thanks
 
Hi FunnyGuy,

Is this in Access? I didn't think you could fill combos like that in Access. I thought you had to use the RowSource and RowSourceType.

Enjoy,
Tony
 
Are you trying to clear the selected value of the combobox or the value list itself?

Alec Doughty
Doughty Consulting P/L

"Life's a competition. Play hard, but play fair"
 
TonyJollans,
You can use the AddItem property of the ComboBox as FunnyGuy has used it here, i just tested it and it works fine.

FunnyGuy,
To clear the value list of the ComboBox you have to make the following assignment.

cmbContactNames.RowSource = "" 'The Zero-Length String

to clear the Selected Value of the ComboBox.

you make an assignment to the value property of the ComboBox of the values NULL, 0, or ""
depending on whether the ComboBox is bound to a control at all, bound to a string, or bound to a number field and dependant on whether the field itself is a Required Field.

Alec Doughty
Doughty Consulting P/L

"Life's a competition. Play hard, but play fair"
 
Hi guys, thanks for the replies,

Yes, this is Access. I am not an expert programmer so I have kinda improvised what I am trying to accomplish. Dont laugh to hard, as I am kinda new to Access.

This will be input for a mailing label report.
I have a form that has customer address info on it. I have 10 different possible contacts (many different tables the info is coming from as well) that this mailing label could be sent to. I have 10 bound contact boxes that cannot be seen on the form. As the user clicks on different aspects of the form, I have gathered all of the contact boxes into a combobox for the user to click on instead of typing out the users name (see above code). Now my problem is trying to clear that damn box when the user clicks on another button to pull up another client address. It adds the new contacts found to the old contacts in the combobox! I have tried to find another way to gather this info with queries (I could do it, but it would mean ALOT of queries. One for each customer), but it I can't seem to find a way to do it. I am a newbie to some extent, so if I am not making any sense please inform me to clairfy something.

Thanks!
 
Thanks alot for your help everyone and thanks for the answer Alec! I was banging my head for awhile on this. Your answer now clears my combobox and my brain.

Shaun
 
FunnyGuy,
To clear the value list of the ComboBox you have to make the following assignment.

cmbContactNames.RowSource = "" 'The Zero-Length String

to clear the Selected Value of the ComboBox you make an assignment to the value property of the ComboBox of the values NULL, 0, or "" depending on whether the ComboBox is bound to a control at all, bound to a string, or bound to a number field and dependant on whether the field itself is a Required Field.

Alec Doughty
Doughty Consulting P/L

"Life's a competition. Play hard, but play fair"
 
Hi Alec,

I have tried this every way I can think of and I have checked and changed and re-ordered references but I cannot get AddItem to work on an Access Form Combobox. Can you give me any clues as to how to do this - because it would be a whole lot easier than dynamically building a Value List.

I CAN add an MSForms combo to an Access Form and then I can use .AddItem but then I can also use .Clear to clear it.

Thanks,
Tony
 
Tony,
Here is the code - exactly as i've got it in my forms module.

There are 2 buttons, 1 comboBox and 1 textBox on this form

I only did this to test whether a comboBox can do this.

Private Sub Command2_Click()
Me.Combo3.AddItem Me.Text5.Value
End Sub

Private Sub Command7_Click()
Me.Combo3.Value = Null
End Sub


NB. This was done using the standard ComboBox control in Access2002. I have just checked Access97 and it's ComboBox control does not have the .AddNew method.

Alec Doughty
Doughty Consulting P/L

"Life's a competition. Play hard, but play fair"
 
Thanks Alec,

I've had a bit of a root around on the M$ website and it looks like this is new in 2002 (I've got 2K). It also looks like it is different in Access from the rest of Office - but still an improvement on the string building needed in 2K and earlier.

Enjoy,
Tony
 
on hte button click event:

comboboxname.setfocus
comboboxname.text=""

i'm not sure thats what you're asking , but hope it helps anyway! worked for me:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top