cheuschober
Muse of Fire
- Local time
- Today, 10:20
- Joined
- Oct 25, 2004
- Messages
- 168
Anyone know why I might be getting a type mismatch error with the following?
The destination table for the Add record uses a byte and a text field, respectively so I'm left a little boggled why it won't add the records.
Thanks,
~Chad
Code:
Private Sub cboBusinessTypeID_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_ErrorHandler
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
Dim strSourceTbl As String
Dim strKeyField As String
Dim strDataField As String
strSourceTbl = "lkupBusinessType"
strKeyField = "BusinessTypeID"
strDataField = "BusinessType"
Dim cn As Connection
Dim rs As ADODB.Recordset
Dim bytKeyID As Byte
If MsgBox(Message1 & NL & Message2, vbQuestion + vbYesNo, Title) = vbYes Then
bytKeyID = 1 + DMax(strKeyField, strSourceTbl, strKeyField <> 255)
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
With rs
.Open strSourceTbl, CurrentProject.Connection, adOpenStatic, adLockPessimistic
.AddNew
.Fields(strKeyField) = bytKeyID
.Fields(strDataField) = NewData
.Update
.Close
End With
Response = acDataErrAdded
Else
Me.cboBusinessTypeID.Undo
Response = acDataErrContinue
End If
Exit_ErrorHandler:
Set rs = Nothing
Set cn = Nothing
Exit Sub
Err_ErrorHandler:
MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
Resume Exit_ErrorHandler
End Sub
The destination table for the Add record uses a byte and a text field, respectively so I'm left a little boggled why it won't add the records.
Thanks,
~Chad