Testing field for null/blank

Malcolmneill

Registered User.
Local time
Today, 23:44
Joined
May 7, 2011
Messages
17
Hi guys,

I need some help, it's a simple problem and I am going nuts trying to make it work!! I want to test a date field on a form to ensure that the user has selected a date using the picker before I update the DB record. Here's my simple code:

If [Date] is Null then

display message

Else

continue processing
end if

:banghead:

I have tried = "" and =" " etc none work. I am sure there's a simple mistake here but......

Really appreciate some help.
 

Attachments

In addition to Plog's spot on advice, generally the way to preculde an null entry on a string field in VBA (rather than the query designer) is to use the IsNull() function - eg.

Code:
If IsNull(Me.YourControl) Then ...

However this won't trap someone entering a zero length string "" or ZLS as it is sometime known. Hence you will often see the following as a catch all code snippet;

Code:
If Len(Me.YourControl & "") = 0 Then ....
 
... or you can use

if Nz([Date], 0) = 0 Then ' blank field
 
Thanks guys, I knew there was a simple answer, I am still pretty new at this!!
 
ensure that the user has selected a date using the picker

For your future knowledge, trying to force a user to use the date picker instead of simply entering a date is not always a good idea. For anyone who is use to touch typing, being able to type in a date is far easier than switching to the mouse to use the picker.

As others have noted, formatting to a date is best. I'd use their default date rather than choosing a specific format though. Internally the date is stored as a number, not how it is typed. As such "1/3/18" and "1 MAR 2018" would be saved internally the same (assuming the 1/3/18 is in D/M/YY format for your local).
 

Users who are viewing this thread

Back
Top Bottom