compile error invalid use of NEW keyword

P

p-rat

I have an application that when a clerk wants to enter in a Work
Ticket they type in the location they are from and it will verify if
the clerk is authorized to enter for said location. There is a table
UserLocation that has an ID (autonumber), user(text), location(text),
dateloggedon(dateandtime).

This works fine in this application.

I am starting on another application for a sister company. Same basic
system. I copied the functions over in a module. I have the exact same
UserLocation table. From the switchboard the clerk will select 'Enter
in Work Ticket' and an input box will ask for location. The code bombs
on the line:

Set rst = New Recordset ' open a recordset

giving a 'compile error invalid use of New keyword'

I looked in the references of the good application and it has ActiveX
2.6 library and on this new one that bombs it has ActiveX 2.1 library.
When I select ActiveX 2.6 and move it up on priority and deselect
ActiveX 2.1 and then close the references it says something to the
affect 'name conflicts with existing module, project, or object
library'.

Here is the code. I am new and someone else wrote the other
application. Didn't know if someone could see what is going on. The
other functions SEEM to be ok, but there again I'm not positive.
Thanks.

Public Function SearchTableByCriteria(strTableName As String,
strCriteria As String) As Boolean

On Error GoTo Err_SearchTableByCriteria
Dim dbs As ADODB.Connection, rst As ADODB.Recordset
Dim strSQL As String, bolRecordFound As Boolean

Set dbs = CurrentProject.Connection ' open the database
Set rst = New Recordset ' open a recordset ' FAILS HERE

If Len(Trim(strCriteria)) > 2 Then
strSQL = "SELECT * FROM [" & strTableName & "] WHERE " &
strCriteria
Else
strSQL = strTableName
End If


rst.Open strSQL, dbs, adOpenStatic, adLockReadOnly

If (rst.RecordCount > 0) Then
bolRecordFound = True
Else
bolRecordFound = False
End If

rst.Close: Set rst = Nothing: Set dbs = Nothing ' disconnect the
database


SearchTableByCriteria = bolRecordFound

Exit_SearchTableByCriteria:
Exit Function

Err_SearchTableByCriteria:
MsgBox Err.Description
Resume Exit_SearchTableByCriteria
End Function
 
D

Danny Lesandrini

Can you be more explicit in the SET statement, using the library in the call ...

Set rst = New ADODB.Recordset

If you don't need both DAO and ADO, then remove one of the references.
BTW, this is just a guess. It's the first thing I'd do. Could be that the DAO
recordset reference is confusing things ... or maybe not.
 

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