473,498 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clearing a XP version combobox

I am trying to figure out how to clear all items from a combobox
(Access 2002).

On my form, I have to comboboxes. Combobox 2 is populated with a set
of child data dependent on the parent data item selected in Combobox 1.
This is done through the .AddItem method of Combobox 2 looping through
the recordset.

This works fine, until --> the data item in the Combobox 1 is changed,
then Combobox 2 just appends the "new" related child data to the what
was previously there. I need it to contain only the data items that
are related to the item currently selected in the Combobox 1.

Apparently, older versions of Access' Combobox had a .Clear method
(???) -- but this seems to be removed from later versions of Access.
The code to fill combobox 2 is as follows:
strSpecies = "SELECT Common_Name FROM Taxa WHERE Taxa.TaxaName = '" &
[Forms]![frm_SelectforEdit]![Combobox_1] & "'"

rst.Open strSpecies, CurrentProject.Connection
Combobox_2.RowSourceType = "Value List"

Do Until rst.EOF
Combobox_2.AddItem rst!Common_Name
rst.MoveNext
Loop

Any help would be appreciated

Nov 13 '05 #1
3 3826
rm*******@operamail.com wrote:
I am trying to figure out how to clear all items from a combobox
(Access 2002).

On my form, I have to comboboxes. Combobox 2 is populated with a set
of child data dependent on the parent data item selected in Combobox 1.
This is done through the .AddItem method of Combobox 2 looping through
the recordset.

This works fine, until --> the data item in the Combobox 1 is changed,
then Combobox 2 just appends the "new" related child data to the what
was previously there. I need it to contain only the data items that
are related to the item currently selected in the Combobox 1.

Apparently, older versions of Access' Combobox had a .Clear method
(???) -- but this seems to be removed from later versions of Access.
The code to fill combobox 2 is as follows:
strSpecies = "SELECT Common_Name FROM Taxa WHERE Taxa.TaxaName = '" &
[Forms]![frm_SelectforEdit]![Combobox_1] & "'"

rst.Open strSpecies, CurrentProject.Connection
Combobox_2.RowSourceType = "Value List"

Do Until rst.EOF
Combobox_2.AddItem rst!Common_Name
rst.MoveNext
Loop

Any help would be appreciated


I am not sure why you need the AddItem process. Why not set the
RowsourceType to Table/Query? And the Rowsource be your SQL statement?

In the ComboBox1 AfterUpdate event enter/do something like
Me.ComboBox2.Requery
Me.ComboBox2 = Null

This will force the values in the combo box to reflect/show all values
that are related to the value in Combo1 and sets the current selection
to nothing.

In regards to your question, maybe the Requery is all you need.
Nov 13 '05 #2
Thanks for the advice. I had tried the RowsourceType and Rowsource
before and they did not work. But after your reply I started from
scratch and tried them again -- it worked great. Not sure what I did
wrong the first time.

Thanks again.

Nov 13 '05 #3
Thanks, I had tried using RowsouceType and Rowsource before, but it did
not work. After your reply, I tried it again from scratch -- and it
worked as it was supposed to. Not sure why I did wrong the first time.
BTW, I need both the combobox.Requery and = Null to get the combobox
to completed clear.

Thanks again......

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2094
by: Newbee | last post by:
Hola I wanted to kno how to clear the current text that is displayed in my combobox I am filling it with a query which is run against my database I have tried this but it not work ...
2
6386
by: Filips Benoit | last post by:
Dear All, Access adp on sql-server 2000 After upgrating to A2003 updating data with 1 perticular combobox causes the program to hangs without any error-msg. Traying to change te combobox...
0
291
by: rmatteson | last post by:
I am trying to figure out how to clear all items from a combobox (Access 2002). On my form, I have to comboboxes. Combobox 2 is populated with a set of child data dependent on the parent data...
5
2256
by: Geoff | last post by:
One of the entries in my subform is a field called . is populated by selecting from its drop down combo box which holds different text options I need to clear session if an invalid entry...
2
5185
by: Brett Romero | last post by:
After I remove all items from a combobox, the last selected item remains in the display area. I've tried: mycbox.SelectedText = string.Empty; and mycbox.refresh(); How do I clear the...
9
2150
by: Beany | last post by:
Hi, i have an address part in my form, i select a site name from a combobox and it automatically populates my address fields..... i have a clear button that has a problem clearing these fields...
1
1728
by: ray well | last post by:
i'm loading a combobox from a database in code, by setting the the DataSouce to a table, and the DisplayMember to a field. it loads the first row into the text area of the combobox automatically....
0
1499
by: Nizha | last post by:
Hi, The browser cache is not getting clearing inspite of setting these headers.. <% response.setHeader("Cache-Control","no-cache"); //HTTP 1.1 response.setHeader("Pragma","no-cache");...
7
3564
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR ...
9
2306
prn
by: prn | last post by:
Hi folks, I've come across a couple of the oddest behaviors that I have ever seen and wondered if anyone else has had anything similar, and if so, whether you have any suggestions for me. I warn...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.