473,375 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,375 software developers and data experts.

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 3815
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
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
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
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
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.