2

I am confused on the conditional operators of VBA. It probably has something to do with weird type casting, but I am stuck and need some help -

query = "SELECT * FROM [records_table] " & _
    "WHERE [po_number] = " & Chr(39) & po_number & Chr(39) & ";"

Set rec_set = data_base.OpenRecordset(query)
MsgBox rec_set.Fields("po_ack")
If rec_set.Fields("po_ack") <> Null Then _
    po_ack = True
If rec_set.Fields("po_ack") = Null Then _
    po_ack = False

Now, this is supposed to return true, but it returns false? When I msgbox the record set value, I get "11/12/2012", but when I msgbox the return of the function, it is false?

po_ack stores a Date value, and the value of this particular one is "11/12/2012", so why when I check it against null, it says that "11/12/2012" == null?

Thanks in advance for any help!

2 Answers 2

3

Null is never equal to anything, not even another Null.

Null is never not equal to anything, not even another Null.

Use the IsNull() function to check whether something is Null.

If IsNull(rec_set!po_ack) = False Then
    po_ack = True
Else
    po_ack = False
End If

See if the IsDate() function could be useful for what you want to do. Here are some sample expressions copied from the Immediate window.

? IsDate(Null)
False
? IsDate(Now())
True
? IsDate("2012-11-12")
True
? IsDate("No way, dood")
False
Sign up to request clarification or add additional context in comments.

Comments

1

Sir I think you should take a look at the links listed below. There is a huge difference between NULL, Nothing and a blank value in VB. Null is something unknown, so it is not equal to 1, TRUE, "" or anything else. Never compare a variable with null because it results in incorrect logic. Check if you are confusing these types.

http://www.techrepublic.com/article/learn-the-differences-between-is-null-and-isnull-in-access/5034252

http://www.everythingaccess.com/tutorials.asp?ID=Common-Errors-with-Null

http://www.tek-tips.com/faqs.cfm?fid=3710

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.