Problems with NotInList code from FAQ

Milothicus

Registered User.
Local time
Today, 08:37
Joined
Sep 24, 2004
Messages
134
I used the code given here which is as follows:

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

On Error GoTo Err_ErrorHandler

' provide text constants to reduce text later and allow for faster execution
' due to added speed from the compilation of constants
Const Message1 = "The data you have entered is not in the current selection."
Const Message2 = "Would you like to add it?"
Const Title = "Unknown entry..."
Const NL = vbCrLf & vbCrLf

' conenction and recordset object variables
Dim cn As Connection
Dim rs As ADODB.Recordset

' show message box and evaluate if the user has selected Yes or No
If MsgBox(Message1 & NL & Message2, vbQuestion + vbYesNo, Title) = vbYes Then
' open a connection to the connection object
Set cn = CurrentProject.Connection ' initialise the recordset object
Set rs = New ADODB.Recordset
' using the recordset object
With rs
.Open "MyTable", cn, adOpenStatic, adLockPessimistic ' open it
.AddNew ' prepare to add a new record
.Fields("MyField") = NewData ' add unfound data into field
.Update ' update the table
.Close ' close the recordset connection
End With
Response = acDataErrAdded ' confirm record added
Else
Me.MyCombo.Undo ' clear the entry in the combobox
Response = acDataErrContinue ' confirm the record is not allowed
End If

Exit_ErrorHandler:
' de-initialise our object variables
Set rs = Nothing
Set cn = Nothing
Exit Sub

Err_ErrorHandler:
' display error message and error number
MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
Resume Exit_ErrorHandler

End Sub

In the blue section, i get a type mismatch error, but i don't know what that connection thing does. i put a break in there, and it spits out a long ugly string that i assume indicates my project, but i really don't know what it is or how to start troubleshooting.

Any help is appreciated
 
for some reason, it didn't like dimensioning cn as connection. I simply replaced cn (in the .open command) with currentproject.connection and it was happy.
 

Users who are viewing this thread

Back
Top Bottom