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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make a combo box be blank (show no data)

Status
Not open for further replies.

KennyUK

Technical User
Sep 13, 2001
38
0
0
GB
Hi,

For various reasons, I need a way (in code if possible) to force a combo box to be displayed on a form blank insted of showing the first item in its list as it is now.

If anyone can help me with the correct syntax or command I would very grateful.

Kind regards,

Kenny
 
Kenny,
I am using this code in the Before Update event of my form & it seems to work fine.

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error Resume Next
cboMyComboBoxName = " "
End Sub

Hope this helps,
Michael MichaelHadden@AltaVista.Com
If you give someone a fish, you have given them a meal. If you teach someone to fish, you have given them MANY meals!
 
Hi Michael,

Thanks for the suggestion but it does not seem to work for for me, Access just sat there and did nothing.

Any other ideas would be gratefully accepted.

Regards,

Kenny
 
Kenny

Try putting Michael's code in the OnCurrent event of your form. This will run every time you move to any record.

HTH

Lightning
 
Hi Lightning,

Nope still dont work and I am placing the code exactly how and where you guys suggest - this is most frustrating.

Allow me to explain further:

I am using Access 2000.

I have a form with a sub form. The sub form has 5 combo boxes on it and the main form has 3 (plus 2 text boxes).

When the user types something that is not in the list of one of the combo's on the main form, an event is triggered to add a new record.
Now the subform automaticly blanks all combos (dont ask me how coz access just does it) but I also need this one combo on the main form to blank as well. At the moment it does not do this, it displays the first record in its list.

So you see my problem, can you suggest any thing please because I am at a loss with something that seems so simple.

Kind Regards,

Kenny
 

How are you populating your combo box? If it is a look-up list from a table or a set value list, try this quick and dirty work-around -

In the look-up list or value list for your combo box, add a blank record by adding a row with " " (a space) as the value. This will always be the first entry in the combo box's list (unless the sort order is Descending).

When your Not In List event fires and the combo box defaults to the first item, it will display a blank, which will of course be over-written when a user makes a selection from the list.

Perhaps not the most hi-tech solution, but it should give you the desired result.

HTH

Lightning
 
Hi Lightning and michael,

Just been messing abnout with this problem and I tried to add a button on the same form as the combo that has the following on the buttons On Click event

comboName = ""

Access gives the following error:

Run Time error '2113'
The value you have entered is not valid for this field.

Dont know if this is important but I thought I'd mention it.

Regards,

KennyUK
 
try Me.comboName.value = ""

combo boxes are a little wierd

paul
 
Lightning,

Hi again, Your "dirty" workaround did the trick but its a little frustrating because I hate being beaten by a problem.

If the = "" solution worked for everyone else, I am the kind that wants to know why i didnt do so for me - I am stubbon like that.

Anyway, thank you for the workaround.

Regards,

Kenny
 
Hi Guys and Gals,

Still have not fixed this problem - anyone got any suggestions please ??

Thanks in advance,

Kenny
 
Kenny,
Is there any way you could e-mail the database to me? If I luck up and fix it I'll send it back. I too like a challenge & wouldn't mind taking a stab at it. Otherwise, I will just give it some thought & let you know if I come up with anything.
- Michael MichaelHadden@AltaVista.Com
If you give someone a fish, you have given them a meal. If you teach someone to fish, you have given them MANY meals!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top