list with inputfield

SeanD

Registered User.
Local time
Today, 23:24
Joined
Mar 9, 2011
Messages
62
Hi all,

I have a table called Customers.
In a form I have a list with inputfield linked to this table.
If you type in a word in this list, and the word is not already in the table, is there a way to put it automaticly in the table?

If tried with the next code when 'If not in list' :
Code:
Private Sub Customer_NotInList(NewData As String, Response As Integer)

Dim dbs As Database, StrSQL As String
Set dbs = CurrentDb
DoCmd.RunSQL ("INSERT INTO Customer (Customer) VALUES (" & Customer.Value & ")")


End Sub

But this won't work
 
If NewData is Sting try this if you want to add without user confirmation.

Code:
Private Sub Customer_NotInList(NewData As String, Response As Integer)
 
Currentdb.Execute "Insert Into Customer (Customer) Values ('" & NewData & "'), dbFailOnError
Response = acDataErrAdded
 
End Sub

JR
 
Last edited:
This query works when I link it to a button

Code:
DoCmd.RunSQL ("Insert Into Customer (Customer) Values ('" & Customer.Value & "');")

But when I put the code in the NotInlist-sub, it does nothing

Code:
Private Sub CustomerNotInList(NewData As String, Response As Integer)

DoCmd.RunSQL ("Insert Into Customer (Customer) Values ('" & Customer.Value & "');")


End Sub
 
Did you try my suggestion? The NotInList event holds the "new" value in the NewData variable, use a refrence to this variable, not the control on the form.

JR
 
Yes, tried it also, but won't work.
If I check with a MsgBox NewData, I get an empty box.
 
No it's a list with inputfield.
Not a combobox
 
Well only comboboxes have a NotInList event so you have to rethink your methode.

So your button approach seems appropriate.

JR
 
It's a listbox with inputfield.
I'm workong in Access 2007 And I have the Dutch version, so it's hard to translate. (I'm Belgian)
The listbox does have the function NotInList.
You can wether select a String from the listbox or type in a String yourself
 
It's a listbox with inputfield.

:confused: Never heard of it. Is it some sort of ActiveX control?

I can't find any NotInList event in listboxes in Access 2010/2007

Perhaps someone else can chime in, but for this sort of thing you really should use the dedicated contol which is Combobox.

JR
 
I think you are confusing your self with the Allow value list edits
Can you doa screen dump of the property sheet.
 
The link you gave as far as I can see this uses a combobox to set some formfilter, not inserting records.

See little demo of using a combobox NotInList event.

JR
 

Attachments

Are you talking about Edit List Items? Probably not the exact name as I don't have 2007 in front of me at the moment.

In the Property Sheet of the control, what Tab is this NotInList under? Events or Data?
 
Are you talking about Edit List Items? Probably not the exact name as I don't have 2007 in front of me at the moment.

In the Property Sheet of the control, what Tab is this NotInList under? Events or Data?

it's under Events
 
Can you do this:

In the Got Focus event of this control, put this:
Code:
Msgbox Me.[COLOR=Red]NameOfControl[/COLOR].ControlType = acListBox
Open your form, click the control and tell us what comes up.
 

Users who are viewing this thread

Back
Top Bottom