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

How can I insert new data in pulldown field??? 2

Status
Not open for further replies.

chubby

Programmer
Apr 28, 2001
278
US
I would like to be able to insert in data a pulldown by just typing in vise going to the table and adding it...
 
Change the limit to list property to No and then you can type anything you want in a pull down. Does this work?

Joe Miller
joe.miller@flotech.net
 
see the FAQ section under access general I believe Elisabeth has a posting on this same thing

you basically use the not in list event then a msgbox to ensure they want to add the entry. on confirmation add the entry to the table via sql or DOA or ADO then refresh the list.

all in just a few lines but too late on a Friday to bother thus the referral to the FAQ
 
Joemiller, when I changed the list property to 'No' it give me this: MS ACCESS can not set the limit ToList to No right now, The first visible column, which is determined by the column widths property, isn't equal to the bound column adjust the column widths property first, and then set the limit to NO. I try it and I lost all my data, so I set it back. I tried changing the column width a number of ways and I still can't get it to work.
 
The message you are getting is because you have set the source of your combo box to be more than one field, and the field you are storing in your table (an id of some sort i assume) is not the field that you are displaying in the combo box.

there is a simple solution to this.

leave the limit to list property as it is.
near the bottom of the properties box is the
on not in list event. use this event to add the new value into the underlying data source of your combo box.

example

I've created a basic two table ordering system as follows:

table customers
customerID, (primary key)
customer, (text)

table orders
orderID, (primary key)
customerID, (number)
details, (text)

From the orders table I create a form, using a combo box for the customerID field. The source of the combo box is

SELECT [customerID], [customer] FROM customers

now leave the limit to list to yes, and build some code in the on not in list event as follows:


Private Sub
CustomerID_NotInList(NewData As String, Response As Integer)
DoCmd.RunSQL ("INSERT INTO customers (customer) VALUES ('" & NewData & "')")
Response = acDataErrAdded
Me.CustomerID.SetFocus

End Sub

all done. ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top