Basic Check for a null value in a form

B

BDM

Hi,

I'm trying to make sure that before someone closes my form, a certain text
box has a value in it. If it doesn't, I want to have a messagebox that
displays a reminder. I've got the message box working when you exit the text
box, but I only want it to come up if the text box is empty.

So far my code looks like this:

Private Sub student_ssn_Exit(Cancel As Integer)
MsgBox ("Social on Exit, How are you doing?")

End Sub

The text box is connected to live data, and is actually text. I'm not sure
why it is saying interger. How do I ad to this to text for a null value,
before the box comes up?
 
T

TomU

To test the contents of the text box use something like this:

If Len(Nz(Me!student_SSN,"")) = 0 then
'The box is empty so do whatever you want to do
End If

Generally, the Before_Update event is the place for this code.

TomU
 
B

BDM

Thanks Tom.

A couple more things:

I'm familiar with the Len function, but what does "Nz" mean? Is that a
function?

Also, I've seen people reference "Me!" and then a field name in a few
entries. Does Me reference the underlying table, or the form name?

Thanks again
 
D

Douglas J. Steele

The Nz function changes Null values to non-null values. The specific one
used below will substitute a zero-length string ("") for Null.

Me refers to the specific instance of the class where the code is executing,
usually a form, but it can also be a report. Note that it's referring to an
object: if you wanted the name of the form, you'd need to use Me.Name
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top