|
-
Jun 30th, 2005, 03:38 AM
#1
Thread Starter
Member
Invalid use of Null !
Hi All,
I am using following code in VBA to get some records (in my case it is a single record). On Message box line it shows "Invalid use of Null" error, How could I prevent this. Is there any method to know any record is there in recordset or not. As if no record is returned then I want to print "No Match".
***************CODE******************************
Set DB = CurrentDb()
'Get Total Actual Project time from TimeSheet
Actprj = "SELECT (Int(CSng(Sum([Duration])))*24)+Format(Sum([Duration]),'hh') & ' : ' & Format(Sum([Duration]),'nn') AS Expr1" _
& " FROM tbTimeSheet HAVING ((tbTimeSheet.PrjID)='" & Form_TmpInfoPrj.cmbPrj.Value & "')"
Set Rst = DB.OpenRecordset(Actprj)
msgbox Rst.Field(0).value
************************CODE***************************
Regards,
Alankar
The rest of mind is not in rest, It rests in rest. 
-
Jun 30th, 2005, 04:09 AM
#2
Addicted Member
Re: Invalid use of Null !
It is always a good practice to check if any records are there in the recordset. The way to do this is
if Rst.Eof and Rst.Bof then
msgbox "No Records returned"
else
msgbox Rst.Field(0).Value
end if
-
Jun 30th, 2005, 04:20 AM
#3
Thread Starter
Member
Re: Invalid use of Null !
Please see my following thread also !
Table update problem !
The rest of mind is not in rest, It rests in rest. 
-
Jun 30th, 2005, 04:50 AM
#4
Re: Invalid use of Null !
In Access:
Nz function (very useful) takes two parameters, the first is the variable you are checking, the second is the default value should the first be null.
In VB/Access:
Isnull function - example : debug.print isnull(rst(0))
Returns true if the variable is null, and false if not.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|