Q. Problems with combo box NotInList event

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
 
J

Jonathan Parminter

-----Original Message-----
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
' 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()ThenSet db = CurrentProject.Connection
'initialize the recordset object
Set rs = New DAO.Recordset
'using the recordset object
'open a connection to the connection object

With rs
.Open "CustomerData", cn, adOpenStatic, adLockPessimistic
' 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
.
Hi Jim,
you have set up procedure to use ado and then changed
declarations to dao without changed associated code.

for example...
Set db = CurrentProject.Connection
'initialize the recordset object
Set rs = New DAO.Recordset
'using the recordset object
'open a connection to the connection object

With rs
.Open "CustomerData", cn, adOpenStatic,
adLockPessimistic

should be...
set db=CurrentDb()
set rs=db.openrecordset("CustomerData")

Use Object Browser for more information on dao recordsets
properties and methods.

Luck
Jonathan
 
J

Jim Jones

-----Original Message-----
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
' 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()ThenSet db = CurrentProject.Connection
'initialize the recordset object
Set rs = New DAO.Recordset
'using the recordset object
'open a connection to the connection object

With rs
.Open "CustomerData", cn, adOpenStatic, adLockPessimistic
' 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
.
Hi Jim,
you have set up procedure to use ado and then changed
declarations to dao without changed associated code.

for example...
Set db = CurrentProject.Connection
'initialize the recordset object
Set rs = New DAO.Recordset
'using the recordset object
'open a connection to the connection object

With rs
.Open "CustomerData", cn, adOpenStatic,
adLockPessimistic

should be...
set db=CurrentDb()
set rs=db.openrecordset("CustomerData")

Use Object Browser for more information on dao recordsets
properties and methods.

Luck
Jonathan

Johathan,

That still doesn't work.
The error now points to the line:


With rs
.Open "CustomerData", cn, adOpenStatic, adLockPessimistic

and highlights "cn"

Are we getting closer to solving this, or further away?

Also, under "References" , Microsoft DAO 3.6 Object Library is
checked.

Can you help further?

Thanks,
Jim
 

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

Top