"Not in list" event code

G

Guest

Hello everyone:

I'm having problems with the below code for adding combo box input if input
is not'
in the list.

What are the variables here that I must change the names of, etc...? I've
tried a couple things but was not successful.

Thank you!


********Code Start******************


Option Compare Database
Private Sub Combo54_NotInList(NewData As String, Response As Integer)

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String

strMsg = "'" & NewData & "' is not an available Document Number Name " &
vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to associate the new Name to the current
DLSAF?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type
it."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("Document Number", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!AEName = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If

End If

Set rs = Nothing
Set db = Nothing
End Sub
'*********** Code End **************
'************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'


Private Sub Document_Number_ID_BeforeUpdate(Cancel As Integer)

End Sub
 
J

JK

The only thing I see missing is an rs.close after the rs.update

What error message are you getting?
 
G

Guest

JK:
Thanks for your reply. I actually got the problem resolved already. Thanks
again!

-Gabriel
 

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