.BOF/ .EOF Giving false results with WHERE statement (1 Viewer)

winshent

Registered User.
Local time
Today, 17:23
Joined
Mar 3, 2008
Messages
162
I'm quite confused by this..

I am testing if a sql recordset contains records.. normal stuff..

The WHERE statement is based on input parameters and will insert either 'LIKE' or 'NOT LIKE' condition on the 'Role' field...

When copying the built SQL into a query and running, both return a number of records.. However, when testing .BOF / .EOF the SQL using 'LIKE' returns TRUE..

Here is my code..

Code:
Public Function gblnProcessData(ByRef pobjConn As ADODB.Connection, pstrDataset As String) As Boolean
    On Error GoTo PROC_ERR

    Dim objRst As New ADODB.Recordset
    Dim strDatasetWhere As String
    Dim strSQL As String

    ' Build WHERE clause based on input parameters
    Select Case pstrDataset
        Case "ORACLE"
            strDatasetWhere = " Role Not Like 'Business Procurement*' "
        Case "IPROCUREMENT"
            strDatasetWhere = " Role Like 'Business Procurement*' "
        Case Else
            MsgBox "Unexpected Dataset Parameter", vbCritical, "Processing Aborted !"
            GoTo PROC_EXIT
    End Select

    strSQL = ""
    strSQL = strSQL & "SELECT RACFID, MaxSequence " & vbNewLine
    strSQL = strSQL & "  FROM Import " & vbNewLine
    strSQL = strSQL & " WHERE " & strDatasetWhere & vbNewLine
    strSQL = strSQL & "ORDER BY RACFID, Role"

    Debug.Print strSQL
    
'    ' Write sequence numbers
    objRst.Open strSQL, pobjConn, adOpenDynamic, adLockOptimistic



    If objRst.EOF Then
        MsgBox "No data has been imported !", vbCritical, "NO DATA !"
    ElseIf objRst.BOF Then
        MsgBox "No data has been imported !", vbCritical, "NO DATA !"
    Else
         ' do some processing

Any ideas ?
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:23
Joined
Aug 30, 2003
Messages
36,118
With ADO, use % as the wildcard.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:23
Joined
Aug 30, 2003
Messages
36,118
Access query and DAO use *, ADO uses %.
 

Users who are viewing this thread

Top Bottom