Date()
If MyTable.Fields("Current_Date")="" then
...
EndIf
The field is empty, but the If statement comes back as false.
I also tried Date(00,00,00) as it says in the online help, but this gives me a syntax error.
Can you please help. Thanks.
From: Gary William
Email: gwilliam@cftnet.com
Fortunately VB gives you a way to deal with this - the IsNull function. You can use it in code like this:
if IsNull(rs.Fields(fieldname)) then
MsgBox "fieldname contains a null value !"
End if
Obviously that's a trivial example but I think you see what I mean. The trick with Nulls is generally figuring out what to do with them in your app. You will need to decide on some strategies for that yourself based upon the data requirements of your app.
Another tip: For avoiding Nulls in String fields when reading them from a recordset you can simply use the following syntax:
txtTextBox.Text = rs.Fields(fieldname) & ""
This simply appends an empty string to each string you read in. Of course if there is a valid string value it has no effect, if the value is Null then it type casts it as a string and the result returned is an empty string.
I hope this helps, check out your VB or Access documentation on Nulls for more info.