You can't use VBA functions when you're running queries against other DBMS.
If you're looking for those accounts that have FR anywhere in them, use LIKE
'%FR%'
Incidentally, you'd be far better off putting that in the WHERE clause
rather than in the HAVING clause. WHERE clauses are evaluated before the
aggregation is done, HAVING clauses are evaluated after. That means your
query may be doing far more accumulation than necessary.
qryDetails = "SELECT BATCHNBR, ENTRYNBR, ACCTID, TRANSNBR, " & _
"FISCALPERD, Sum(TRANSAMT) AS TRANSAMOUNT " & _
"FROM GLPJD " & _
"WHERE BATCHNBR >= '363361' " & _
"AND ACCTID LIKE '%FR%' " & _
"GROUP BY BATCHNBR, ENTRYNBR, ACCTID, TRANSNBR, FISCALPERD " & _
"ORDER BY BATCHNBR ASC;"
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"Ron" <(E-Mail Removed)> wrote in message
news:F6FAE141-523A-4490-B9CF-(E-Mail Removed)...
>I am trying to pull a record set from our financial software's database. I
> only want GL accounts that are associated with a certain location. The GL
> Accounts use the sturcture GLCODE-LOCATION. I am using the OLE DB driver
> to
> access the data. Here is a snippet of my code
>
> Const CONNECTION As String = "Provider=PervasiveOLEDB;Data
> Source=DB;Location=SERVER;"
> Dim CN As ADODB.connection
> Dim rsQuery As ADODB.Recordset
> Dim rsDetails As ADODB.Recordset
> Dim qryDetails As String
>
>
> 'open a connection to the database
> Set CN= New ADODB.connection
> CN.Open CONNECTION
>
>
> 'Create Query to retrieve transaction details
> qryDetails = "SELECT BATCHNBR, ENTRYNBR, ACCTID, TRANSNBR, FISCALPERD,
> Sum(TRANSAMT) AS TRANSAMOUNT " & _
> "FROM GLPJD " & _
> "WHERE BATCHNBR >= '363361' " & _
> "GROUP BY BATCHNBR, ENTRYNBR, ACCTID, TRANSNBR, FISCALPERD
> " & _
> "HAVING InStr(ACCTID, 'FR') <> 0 " & _
> "ORDER BY BATCHNBR ASC;"
> '"HAVING InStr(ACCTID, 'FR') <> 0 "
>
> Set rsDetails = New ADODB.Recordset
> Set rsDetails.ActiveConnection = CN
> rsDetails.Source = qryDetails
> rsDetails.LockType = adLockReadOnly
> rsDetails.CursorType = adOpenKeyset
> rsDetails.Open
>
> I am unable to upen the recordset. I get the following error:
>
> -2147467259 -->[LNA][ODBC Engine Interface] Error in expression:
> InStr(ACCTID, 'FR').
>
> I have also tried "HAVING CharIndex('FR', ACCTID) <> 0 " and that
> doesn't
> work either. anyone have a solution to my error?
>
> Thanks in advance.