J
Jim Jones
Hi,
It was suggested that I make a new post for this problem.
My problem: When I enter a name that's not in my combobox, and hit
enter,
I get the following error below: (I've included the code for the
notinlist event):
First:
Compile Error:
Invalid use of NEW keyword.
Here is the code for the Notinlist event:
**************************************************************************
Private Sub Combo133_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
'connection and recordset object variables
'Dim cn As ADODB.Connection
'Dim rs As ADODB.Recordset
Dim db As DAO.Database 'DAO
Dim rs As DAO.Recordset ' DAO
'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 db = CurrentProject.Connection
'initialize the recordset object
Set rs = New DAO.Recordset
'using the recordset object
With rs
.Open "CustomerData", cn, adOpenStatic, adLockPessimistic
' open it
.AddNew ' prepare to add a new record
.Fields("Combo133") = NewData ' add unfound data into field
.Update ' update the table
.Close ' close the recordset connection
End With
Response = acDataErrAddes ' 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
*****************************************************************************
Then,
SOMETIMES, if I backspace over the entry I've typed, that's not in the
combo box (after exiting
out of the vbEditor), and try to click in the Customer Last name field
to enter
the last name, it may OR may not let me do it.
In which case, if it gives me another error, it takes me back to the
vbEditor,
to the following lines of code, which were created for the combo box:
Private Sub Combo133_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[CustomerNumber] = " & Str(Me![Combo133]) (This gets
hilighted)
Me.Bookmark = rs.Bookmark
End Sub
Thanks,
Jim
It was suggested that I make a new post for this problem.
My problem: When I enter a name that's not in my combobox, and hit
enter,
I get the following error below: (I've included the code for the
notinlist event):
First:
Compile Error:
Invalid use of NEW keyword.
Here is the code for the Notinlist event:
**************************************************************************
Private Sub Combo133_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
'connection and recordset object variables
'Dim cn As ADODB.Connection
'Dim rs As ADODB.Recordset
Dim db As DAO.Database 'DAO
Dim rs As DAO.Recordset ' DAO
'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 db = CurrentProject.Connection
'initialize the recordset object
Set rs = New DAO.Recordset
'using the recordset object
With rs
.Open "CustomerData", cn, adOpenStatic, adLockPessimistic
' open it
.AddNew ' prepare to add a new record
.Fields("Combo133") = NewData ' add unfound data into field
.Update ' update the table
.Close ' close the recordset connection
End With
Response = acDataErrAddes ' 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
*****************************************************************************
Then,
SOMETIMES, if I backspace over the entry I've typed, that's not in the
combo box (after exiting
out of the vbEditor), and try to click in the Customer Last name field
to enter
the last name, it may OR may not let me do it.
In which case, if it gives me another error, it takes me back to the
vbEditor,
to the following lines of code, which were created for the combo box:
Private Sub Combo133_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[CustomerNumber] = " & Str(Me![Combo133]) (This gets
hilighted)
Me.Bookmark = rs.Bookmark
End Sub
Thanks,
Jim