G
Guest
What is the proper method of matching to a NULL value in VBA code? 'Is Null'?
'=Null'? Other?
I have a form through which users add data that gets apprended to a table
via a SQL string. This SQL string fails via End...debug error if any of the
fields are left blank. Instead of simply failing each time, returning an
error regardless of which null value it failed on, I am setting up a series
of If statements which check each of the fields (6 total) for a lack of
information, then return a message indicating which one(s) it failed on, and
changing the .backcolor of the fields to red.
If I leave a field blank, (Me.Analyst for example) I get different results
depending on how I set up the if statement
If I try:
"If Me.Analyst = Null Then"
the If returns FALSE, ignoring the MsgBox code, even though when I add a
breakpoint and take a look at the value, the field value shows as 'Null'. The
code continues on and errors on the SQL statement.
If I try:
"If Me.Analyst Is Null Then"
the If statement generates an error 'invalid object'.
I can't bind this to a table given the circumstances, and since 4 of the 6
values are text strings of whatever the users type in, there is nothing I can
clearly match on other than 'is null'. The fields begin completely blank, not
assigned any value.
Thanks.
'=Null'? Other?
I have a form through which users add data that gets apprended to a table
via a SQL string. This SQL string fails via End...debug error if any of the
fields are left blank. Instead of simply failing each time, returning an
error regardless of which null value it failed on, I am setting up a series
of If statements which check each of the fields (6 total) for a lack of
information, then return a message indicating which one(s) it failed on, and
changing the .backcolor of the fields to red.
If I leave a field blank, (Me.Analyst for example) I get different results
depending on how I set up the if statement
If I try:
"If Me.Analyst = Null Then"
the If returns FALSE, ignoring the MsgBox code, even though when I add a
breakpoint and take a look at the value, the field value shows as 'Null'. The
code continues on and errors on the SQL statement.
If I try:
"If Me.Analyst Is Null Then"
the If statement generates an error 'invalid object'.
I can't bind this to a table given the circumstances, and since 4 of the 6
values are text strings of whatever the users type in, there is nothing I can
clearly match on other than 'is null'. The fields begin completely blank, not
assigned any value.
Thanks.