Link to home
Start Free TrialLog in
Avatar of Todd MacPherson
Todd MacPhersonFlag for Canada

asked on

Problems with null in an SQL

Hello Experts

I am trying to figure out why my SQL is returning EOF = False and throwing an error when there is no value in the table that has a woodcat = Logs and Diameter >= 24

In other words this query, based on the current table I have, should return EOF = True and I do not know why it does not.

Please help.

Thanks

PBLack

The code below throws the following error:

Runtime Error. Invalid use of Null

Dim db as database
Dim strVol as string
Dim recVol as Recordset
Dim logs24 as Double
logs24=0

Set db = CurrentDb()

strVol = "SELECT Sum(VOLHA) AS TOTVOL FROM tblMTally WHERE woodcat = 'Logs' AND ta_dbh >= 24;"
Set recVol = db.OpenRecordset(strVol, dbOpenDynaset)

With recVol
    If .EOF = False Then
        .MoveFirst
        logs24 = Nz(CDbl(!TOTVOL), 0) 'error thrown on this line
    End If
End With
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Todd MacPherson

ASKER

Yours is not working either and I see why from your code. The recordcount is showing 1 but I just confirmed manually (114 records in table) that there is no record with woodcat 'Logs' and ta_dbh >= 24.

I am perplexed.
Yep that is is. Split the points evenly. It has been a long day. Thanks Experts!
PBlack,

it is a lot easier to read these threads if you indicate who you are talking to when you enter a reply.
@fved sorry dude. I originally replied without seeing the other comments. Duly noted and wont happen again.