By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 2,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

Dim'ing a var as Long, then assigning it to an expression that eval's to #NULL# - Is that a problem?

P: n/a
MLH
Tell me if this assignment should return "Invalid use of Null" error:

Dim RememberedReportNum AS Long
RememberedReportNum = DLookup("[CredReptID]", "[tblCreditReports]")
While considering your response, here's what the DLookUp returns:
? DLookup("[CredReptID]", "[tblCreditReports]")
#NULL#
Can RememberedReportNum not receive the value of #NULL# ?
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
it shouldn't be able to. Null is not a number. It's not a zero. It
means "value unknown".

If you have to be able to assign a null value to a variable, then
declare it a variant, not a long.

Nov 13 '05 #2

P: n/a
"MLH" wrote in message:
news:hb********************************@4ax.com...
Tell me if this assignment should return "Invalid use of Null" error:

Dim RememberedReportNum AS Long
RememberedReportNum = DLookup("[CredReptID]", "[tblCreditReports]")

While considering your response, here's what the DLookUp returns:
? DLookup("[CredReptID]", "[tblCreditReports]")
#NULL#

Can RememberedReportNum not receive the value of #NULL# ?


Only Variant data types can handle Null values.

Consider this example behind a command button for illustration:

Private Sub Command0_Click()

Dim RememberedReportNum As Long
RememberedReportNum = DLookup("[CredReptID]", "[tblCreditReports]")

If IsNull(RememberedReportNum) = True Then
MsgBox "It is Null"
Else
MsgBox RememberedReportNum
End If

End Sub

Pressing the button will yield Error 94, Invalid use of null.

Now change it to a Variant and see what happens:

Private Sub Command0_Click()

Dim RememberedReportNum As Variant
RememberedReportNum = DLookup("[CredReptID]", "[tblCreditReports]")

If IsNull(RememberedReportNum) = True Then
MsgBox "It is Null"
Else
MsgBox RememberedReportNum
End If

End Sub

This time the message box saying it is null appears.
--
Jeff Conrad
Access Junkie
Bend, Oregon

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 13 '05 #3

P: n/a
MLH wrote:
Tell me if this assignment should return "Invalid use of Null" error:

Dim RememberedReportNum AS Long
RememberedReportNum = DLookup("[CredReptID]", "[tblCreditReports]")
While considering your response, here's what the DLookUp returns:
? DLookup("[CredReptID]", "[tblCreditReports]")
#NULL#
Can RememberedReportNum not receive the value of #NULL# ?


Yes.
? NZ(DLookup("[CredReptID]", "[tblCreditReports]"),0)
Nov 13 '05 #4

P: n/a
MLH
Thx 2 U all for your comments.
I'm hip now to the Variant. I'll
take care of it.

Warmest regards.
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.