Checking for a null value in a text box

  • Thread starter George Papadopoulos
  • Start date
G

George Papadopoulos

Hello Access users,


I have written the code below, which is part of an event handler I`m using
:

If Me.From_Date <> Null Then dtFrom_Date = Me.From_Date
If Me.To_Date <> Null Then dtTo_Date = Me.To_Date.

The code is supposed to check if the text box 'From_Date' has some value
before assignment. Unfortunately, the statement fails and the variable
dtFrom_Date (Date type) takes on an undefined value.

Is this the recommended approach to check for empty values in a text box?

thx, in advance

George Papadopoulos
 
M

MacDermott

To check for Null, use
If IsNull(Me.From_Date)
to check for not Null, you can use
If Not IsNull(Me.From_Date)
Remember, though, that an unbound textbox may contain a blank string and
look just as empty as one which contains a Null value.
Because of that, I sometimes use a condition like this:
If Me.From_Date & ""=""

HTH
- Turtle
 
T

Treebeard

If IsDate(Me.From_Date) Then dtFrom_Date = Me.From_Date
If IsDate(Me.To_Date) Then dtTo_Date = Me.To_Date.
 

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