Not in list event form

  • Thread starter Thread starter Bessie Sanders
  • Start date Start date
B

Bessie Sanders

Hello,

I am having some problems with the not in list event. I
want the staff to add a new customer inturns, it will take
them to the customer form. This is what I have so far:

Private sub customerID_notinlist(newdata as string,
response as integer)
dim db as dao.database
dim rs as dao.recordset
dim strmsg as string

if NewData = " " then exit sub

strmsg = " ' " & NewData & " is not in the list. " &vbcr
&vbCr
strmsg = strmsg & "do you want to add this customer?"

if msgbox(strmsg, vbQuestion + vbYesNo) = vbYes then
DoCmd.OpenForm"customers",,,,acAdd, adCialog, NewData
else
response = acDataErrcontinue

strmsg = strmsg & "Customer is added."
response = vbOKOn

response = acDataErrAdded
rs.close
re.update
end if
exit sub
end sub

When I try to add the new customer name this what pops
up "The text you entered, isn't an item in the
list." "Select an item from the list, or enter text that
matches one of the listed items. OK"

I been working on this for a couple of days and the same
thing keep poping up. Also, I have 6,000 record in this
database could this had affect of why adding new names
stop working?

Thanks in advance
Bessie
 
Not sure where you go that example code from, but all you need is:


Private sub customerID_notinlist(newdata as string, response as integer)

Dim strmsg As String

If NewData = " " Then Exit Sub

strmsg = NewData & " is not in the list. " & vbCr & _
vbCr & "do you want to add this customer?"

If MsgBox(strmsg, vbQuestion + vbYesNo) = vbYes Then
DoCmd.OpenForm "customers", , , , acAdd, adCialog, NewData
response = acDataErrAdded
Else
response = acDataErrContinue
End If


end sub

The above is all the code you need...
 
Hi Bessie,

To begin with, for you to be able to add an item to a combo on the fly you
have to set the combo's "Limit To List "property to True. This will trigger
the NotInList event.

Assuming that the customer form adds the new customer successfully then you
just set a global variable blAdded (In a module) to True from the form.
When the form is closed and your code continues, you can chack if the
customer was added. If it was added you set the response parameter to
acDataErrAdded, which will cause Access to requery the comboand select the
newly added item.
If customer was not added you set the response parameter to
acDataErrcontinue.
I don't know what you are using the db and rs variables for, since you are
adding the customer with a form
All the code you should need is as below;

Private sub customerID_notinlist(newdata as string,
response as integer)
dim strmsg as string

if NewData = " " then exit sub

strmsg = " ' " & NewData & " is not in the list. " &vbcr
&vbCr
strmsg = strmsg & "do you want to add this customer?"

if msgbox(strmsg, vbQuestion + vbYesNo) = vbYes then
DoCmd.OpenForm"customers",,,,acAdd, acDialog, NewData
if(blAdded = True) then
response = acDataErrAdded
msgbox("Customer was added")
else
response = acDataErrcontinue
end if
else
response = acDataErrcontinue
end if

End Sub
 
Back
Top