Not In List CBO Help

S

Stockwell43

Hello,

I have a CBO on my form named Catagory. It is bound to a table called
tblCatagory. I tried to place this code in the On Not In List event of the
CBO and when I typed in a catagory not in the table, not only did not warn me
but also it did not save it to the table. can someone help me please?
This is the code I used from a site on the internet:

Private Sub Catagory_NotInList(NewData As String, Response As Integer)

On Error GoTo cboCatagory_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The Catagory " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Acme Oil and Gas")
If intAnswer = vbYes Then
strSQL = "INSERT INTO tblCatagory([Catagory]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new Catagory has been added to the list." _
, vbInformation, "Acme Oil and Gas"
Response = acDataErrAdded
Else
MsgBox "Please choose a Catagory from the list." _
, vbInformation, "Acme Oil and Gas"
Response = acDataErrContinue
End If
cboCatagory_NotInList_Exit:
Exit Sub
cboCatagory_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume cboCatagory_NotInList_Exit
End Sub

Thank you any help you can offer!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top