Problem with .EOF and .BOF

rede96

Registered User.
Local time
Today, 12:07
Joined
Apr 2, 2004
Messages
134
I'm using the DOA.Recordset method to open a recordset based on a SQL statement. (SELECT * FROM ....)

I then use 'If Not (rst.EOF and rst.BOF) then' ... to check if the recordset is populated.

This normally works fine except when I use some sort of Group by, Max etc. in the SQL statement. In this case, even when there are no records, the .EOF and .BOF read false. I even get a record count of 1.

Am I doing something wrong in the way that I am generating the recordset?

An example of my SQL would be as follows:

Code:
    strSQL = "SELECT Max(Tbl_ScanResults.EndTimeStamp) AS EndTimeStamp " & _
    "FROM Tbl_ScanResults WHERE (((Tbl_ScanResults.ScannerID)='" & MyScanID(i) & "') AND " & _
    "((DateValue([EndTimeStamp]))=DateValue(Now())));"

Any help would be much appreciated!
 
Last edited:
If you debug.print your sql statement and run it in the query window what result do you get?

I'm also a little wary of calling the max() value alias the same as the field name, pretty sure access has a bit of a hissy fit when you do that sometimes...
 
I find Access throws a 'massive wobbly' when it doesn't like what I want it to do...
 
Only if the settings are set to "Queen's English"...
 
Sorry for hijacking your thread Rede96...I would offer a suggestion, but I can't improve upon Minty's.
 
If you debug.print your sql statement and run it in the query window what result do you get?

I'm also a little wary of calling the max() value alias the same as the field name, pretty sure access has a bit of a hissy fit when you do that sometimes...

The SQL looked fine and worked fine for records that were populated.

However...after putting the SQL back into a normal query and playing around with it, I noticed it changed the SQL to using HAVING and GROUP BY instead of WHERE.

Code:
    strSQL = "SELECT Max(Tbl_ScanResults.EndTimeStamp) AS EndTimeStamp FROM Tbl_ScanResults " & _
    "GROUP BY Tbl_ScanResults.ScannerID, DateValue([EndTimeStamp])HAVING " & _
    "(((Tbl_ScanResults.ScannerID)='" & MyScanID(i) & "') AND ((DateValue([EndTimeStamp]))=DateValue(Now())));"

So I changed my SQL for my recordset and .EOF/.BOF now work...:confused:

Typical female operating system. There's always a number of ways to ask, but if you don't ask in the right way... :)
 
Typical female operating system. There's always a number of ways to ask, but if you don't ask in the right way... :)

Quite right, thanks for marking the thread as "solved"
 
Glad you sorted it - I think it would work quicker with

((DateValue([EndTimeStamp]))=Date())

As you wouldn't be converting Now() to the current date for each record. (I suspect we're not talking earth shattering performance differences here...)
 

Users who are viewing this thread

Back
Top Bottom