how to clear Combo box

G

Guest

How can I clear a combo box. ie., I want to reload the combo. Like in VB
comboName.Clear is there but in MS Access how to clear the values and Reload
the value. Actually I lad the combo like this ...
rec.open "SELECT EMP_ID from EMP_mast ", adoopenforwardonly,adlockreadonly
while rec.eof = false
mycombo.additem rec!Emp_ID
rec.movenext
wend

Thanks in Advance.....
 
C

Carl Rapson

Karthikeyan Periasamy said:
How can I clear a combo box. ie., I want to reload the combo. Like in VB
comboName.Clear is there but in MS Access how to clear the values and
Reload
the value. Actually I lad the combo like this ...
rec.open "SELECT EMP_ID from EMP_mast ",
adoopenforwardonly,adlockreadonly
while rec.eof = false
mycombo.additem rec!Emp_ID
rec.movenext
wend

Thanks in Advance.....

You should be able to clear a combo box by clearing its Row Source:

mycombo.RowSource = ""

As a note, however, you could set the Row Source of the combo box directly
to the SQL statement:

mycombo.RowSource = "SELECT EMP_ID from EMP_mast"

Just change the RowSourceType to Table/Query first.

Carl Rapson
 
M

Mr. B

How can I clear a combo box. ie., I want to reload the combo. Like in VB
comboName.Clear is there but in MS Access how to clear the values and Reload
the value. Actually I lad the combo like this ...
rec.open "SELECT EMP_ID from EMP_mast ", adoopenforwardonly,adlockreadonly
while rec.eof = false
mycombo.additem rec!Emp_ID
rec.movenext
wend

Thanks in Advance.....

Actully in Access you do not have to use the AddItem method. You
simply set the Row Source to an sql statement or query that returns
the recordset you want. You can have multiple colums of information
in any combo box but only show one column in the box. You can bind
any column but show multiple columns of info when the list is droped
down.

When you want to refresh the list (say after adding a new record to
the table(s) from which the combo box gets its data, just use:

me.NameOfControl.Requery

If you need to actually change the source (completey different sql
statement or query) just redefine the row source and requery the combo
box.

with me.NameOfControl
.rowsource = strSql '(variable that holds the sql string or us
the name of a query)
.requery
end with

HTH

Mr B
 
G

Guest

Thank you verymuch for ur reply.... Its really usefull for me.
But In some case
Form!Myform!Mycombo.requery
is not load the combo with the Recently inserted value. ie., its not
refreshing again.
Can u help be for above problem?
 
G

Guest

Thank u very much.. for ur reply...,
I changed that combo load from Additem to Rowsource. Its working fine.
If i want to refresh the combo with recently inserted value. I wrote the
code like this. Form!Myform!Mycombo.Requery. some time Its not refreshing
the combo....?
can u please help me?....
 
C

Carl Rapson

How are you inserting the value? It may be that you are requerying your
combo box before the Insert is written to the database.

Carl Rapson
 

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

Top