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

Clear Combo Box Before Opening New Form 2

Status
Not open for further replies.
May 21, 2003
64
US
I have a form where you can enter an invoice and then the associated products subform. The products are controlled by a combo box tied to a primary key field. The user begins by typing the product into the combo. If they start to type and their product isn't in the list, they need to hit a button that triggers the add record form.

I'm having a problem with the keyed data currently in the combo box. If they key a partial or complete product number like 55555, realize it isn't in the list and hit the add button, I get an error because 55555 isn't currently in the list. To avoid the error the user needs to hit escape 3 times, which clears the combo box. Then they can hit the add button without the error.

Is there a way to delete, clear, etc. the info in the current field (the combo box) before (or during) the time they click the add record button? That way they could seamlessly avoid the error. Any help would be appreciated. Thanks.
 
What code do you have on the Add Record button??

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
normally I use a different approach to doing this than you have, but what you can do is to put some code to resett the value of your combo box in the onClick event of your button.

I suggest you use the .undo function, you only have to use it once.

--------------------
Procrastinate Now!
 
The add record button triggers a macro that brings up the add record form, then closes the add record form, closes the main form, reopens the main form (to refresh the data) then uses a goto to go to the last record where the newly entered product can then be selected. I know it's a bit clunky but it works pretty well.

I'm not too familiar with code, but will look into the .undo function and see what I can do. Thanks.
 
Hi Derek!

Try these FAQs:

faq702-4283
faq181-66
faq181-110

They all talk about using the notinlist error to add new information to the data source of the combobox.

hth


Jeff Bridgham
bridgham@purdue.edu
 
How are ya derekstewart . . . . .

I'd remove the button and do whats required (add/cancel) thru the [blue]NotInList[/blue] Event of the combobox(thats what its for).

Calvin.gif
See Ya! . . . . . .
 
You could type code on the on_click event of the Add New Record button. Simple enter

comboxname.value = ""
Docmd.OpenForm "Name of the form you want to open"

Note: You will still get the popup box reporting the text entered was not in the list.

Where comboboxname = the actual name of your combobox. Although you should really be using the In Not in List event of the combobox to take proper action. The code there would be something like this.

Private Sub ComboboxName_NotInList(NewData As String, Response As Integer)
ComboboxName.Value = ""
DoCmd.OpenForm "Your Data Entry Form"
End Sub

Make sure to Add a docmd.runcommand.accmdrefresh to the close button of your data entry form so that the new entry appears on your combo box after you close the data entry form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top