clearing data in combo box

  • Thread starter Thread starter clueless2003
  • Start date Start date
C

clueless2003

Guest
Before I forget...I've got yet another combo box question. Then I'm going to bed--I swear!

I don't like the fact that the user (of my form) has to manually clear the combo box text prior to putting in a new value. Does anybody have any ideas how I might be able to make this process "neater"? I'm open to idea!

Thanks in advance!
 
insert:
Code:
me.combo1=""
into either the afterupdate events or gotfocus events of the combo box or some other event that makes sense for the combo box to be cleared or reset.
 
Calvin, setting the combo box value to "" makes it a zero-length string. That solution will work in many real-world situations, but technically speaking, it doesn't truly empty the value of the combo box.

When an unbound combo box is initialized on a form, the value is actually equal to Null (unless you've set a default value), and you can use Me.cbo = Null to reset it to the "initial" value.

Setting it equal to "" will probably work for what the user wants, but can cause problems in search forms and forms where a recordset is produced via dyanamic SQL coding.
 
I use

me.YourComboName.defaultvalue = ""

I have found that by using

me.YourComboName = Null
me.YourComboName.DefaultValue = Null

or an equivelant makes the user press Esc to clear the field before they can close the form.

Also can someone please tell me why you put Me. in front of the command name.? My code works fine without it. Is it used so you can select the command name instead of having to type it, or is there a more significant reason.
 
[Using null] or an equivelant makes the user press Esc to clear the field before they can close the form.
Interesting. I haven't found that to be true in my forms. But, bottom line is - whatever works!

The Me keyword is used to refer to the current form or report that contains the class module in which you are writing your code. If your current form is called frm, then it's the same as writing Forms!frm etc...

A big side benefit of using it, as you've found, is that it lets you select properties and methods from a drop-down list.
 

Users who are viewing this thread

Back
Top Bottom