Checking for a null value in a text box

  • Thread starter Thread starter George Papadopoulos
  • Start date 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
 
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
 
If IsDate(Me.From_Date) Then dtFrom_Date = Me.From_Date
If IsDate(Me.To_Date) Then dtTo_Date = Me.To_Date.
 
Back
Top