Run-time error 94, invalid use of null

ylp

Registered User.
Local time
, 17:01
Joined
Mar 25, 2010
Messages
42
HI,

I need read data from a table, my code :

strSQL = "SELECT time,Amount," _
& " Where sampleDateTime = " & "#" & lastDayOfPreviousMonth & "# ;"

Set rs = CurrentDb().OpenRecordset(strSQL)
If rs.EOF Then
'MsgBox .Show(no data)
Else
mTime = rs.Fields("time")
mAmount = rs.Fields("Amount")
End If

rs.Close
Set rs = Nothing

The strSQL in immediate window:
SELECT time,Amount from tblTest Where sampleDateTime = #2/28/2010# ;

And all rs field get null value, but I do have value in the database, what is wrong?

Thanks.
 
Does the SQL produce a result if you copy it from the Immediate window to a new query? I note you have a comma after amount while building the SQL, but not in the string from the Immediate window. One of those is wrong. If sampleDateTime contains a time component, you'll need to account for that.
 
Also TIME is an Access Reserved Word (not a good idea to use for a field or object name). You need to enclose it in square brackets in order for it to have a chance at working.
 
Hi, thanks for all your reply.

I check the query and found no data returned, after add one more criteria, got the data. Thanks so much!

Another problem:
I have a continuous form which displays one month's data, but always got one more empty row for every month, how to delete this additional row?

Many thanks.
 
It sounds like the row for a new record. Try setting the Allow Additions property to No.
 
HI,
After I set AllowAdditions to No, got an error:

Run-time error 2763, DTPicker returned the error: property is read-only.

And no data displayed at all on the form.

Many thanks!!
 
Hi,
Got same error but in differenct situation, there is nothing in txt1( it holds decimal value), but it runs to Else, then got the same error,thank for reply.

If Me.txt1.Value = "" Then ' Also trie =null, same error
var = 0
Else
var = Me.txt1
End If
 
How about this:

Code:
If Len(Me.txt1 & "") = 0 Then 
   var = 0
Else
   var = Me.txt1
End If
 
Thanks very much, it works great!

Any suggestion about allowAdditions?
 

Users who are viewing this thread

Back
Top Bottom