Null vs New Record

jversiz

New member
Local time
Yesterday, 21:18
Joined
Feb 19, 2008
Messages
4
Hello Smart People!

This one is driving me nuts. After doing quite a bit of research, I cannot find the answer that I need, so I am posting...

For a new record on frm1 I am trying to make the label (lblTest) for a text box named txtTest a certain color if a value has not been filled in. For some reason, I cannot get the code to work and I am guessing it is due to my lack of understanding of our good old friend NULL. Here is what in both the after update event for txtTest and the on current event for the form...

If Me.txtTest = Null Then
Me.lblTest.ForeColor = 255
Me.lblTest.FontBold = True
Else
Me.lblTest.ForeColor = 0
Me.lblTest.FontBold = False
End If

Why isn't the field red when I create a new record? Why is it that if I fill something into the field, then delete it, that it doesn't get bolded in red?

Regards,
James C.
 
Well, nothing is ever = Null, so this should work

If IsNull(Me.txtTest) Then

Personally I would use Conditional Formatting for this though.
 
You Rock!

Thanks for the quick response. It works great!

I originally wanted to use conditional formatting, however conditional formatting is only available for the text box itself, not it's label.

Again, thank you very much!

Best Regards,
James C.
 
Ah, you're right about the label. I format the required text boxes themselves, so users can see at a glance what fields they've missed. Glad you got it sorted.
 
Well, nothing is ever = Null, so this should work

If IsNull(Me.txtTest) Then

Personally I would use Conditional Formatting for this though.

You are the man! I was beating my head against a wall until I read this...

Code:
If Me.txtField.Value = "" Then

The above apparently doesn't work correctly. Huh. Thanks!
 
That would work, but wouldn't test for Null, just a zero length string (they're different, even though they look the same). Glad I helped though!
 
for the benefit of airforceruss

if you get a sutuation where it might be null OR a zero length string (zls)then

If nz(Me.txtField.Value,"") = "" Then

etc, deals with both situations

btw, i think MS recommend using vbnullstring rather than explicitly ""

its just that vbnullstring is guaranteed to work in any breed of Access, but "" may not
 

Users who are viewing this thread

Back
Top Bottom