If then Statement

V

Vadimbar

Hello I have two if then statements.
1. If [Text40] = "" Then
[Text40] = Now()
End If
works just fine I can step through it no problem.

2.If [Text46] = "" Then
[Text46] = Now()
End If
Always bypasses the then statement and goes directly to End if. Even though
the value is null. What could be causing this?
The fields are the same type in every way. Any ideas?

Thank you
Vadimbar
 
K

Ken Snell \(MVP\)

Null is not equal to "". Null is not equal to Null. Null is not equal to
anything.

Use the IsNull function to test for whether a value is Null:

If IsNull([Text46]) = True Then
[Text46] = Now()
End If

However, the above will be false if the value actually is an empty string.
So, I usually use this approach, which captures both a Null and "" value:

If Len([Text46] & "") = 0 Then
[Text46] = Now()
End If
 
O

Ofer Cohen

You need to check for Null value and not only empty value

If [Text46] = "" Or IsNull([Text46]) Then
[Text46] = Now()
End If

Or, try
If ([Text46] & "") = "" Then
[Text46] = Now()
End If
 
M

molsonexpert

your code suggests 'if text46 is blank, then make it now()'

there's a big difference between null and blank. try changing it to if
[text46] is null then...
 
V

Vadimbar

Thank you I tried using Null earlier but I must have used the wrong syntex.
Thank you it worked.

Ofer Cohen said:
You need to check for Null value and not only empty value

If [Text46] = "" Or IsNull([Text46]) Then
[Text46] = Now()
End If

Or, try
If ([Text46] & "") = "" Then
[Text46] = Now()
End If

--
Good Luck
BS"D


Vadimbar said:
Hello I have two if then statements.
1. If [Text40] = "" Then
[Text40] = Now()
End If
works just fine I can step through it no problem.

2.If [Text46] = "" Then
[Text46] = Now()
End If
Always bypasses the then statement and goes directly to End if. Even though
the value is null. What could be causing this?
The fields are the same type in every way. Any ideas?

Thank you
Vadimbar
 
V

Vadimbar

Great thank you.

Ken Snell (MVP) said:
Null is not equal to "". Null is not equal to Null. Null is not equal to
anything.

Use the IsNull function to test for whether a value is Null:

If IsNull([Text46]) = True Then
[Text46] = Now()
End If

However, the above will be false if the value actually is an empty string.
So, I usually use this approach, which captures both a Null and "" value:

If Len([Text46] & "") = 0 Then
[Text46] = Now()
End If

--

Ken Snell
<MS ACCESS MVP>




Vadimbar said:
Hello I have two if then statements.
1. If [Text40] = "" Then
[Text40] = Now()
End If
works just fine I can step through it no problem.

2.If [Text46] = "" Then
[Text46] = Now()
End If
Always bypasses the then statement and goes directly to End if. Even
though
the value is null. What could be causing this?
The fields are the same type in every way. Any ideas?

Thank you
Vadimbar
 
V

Vadimbar

Thank you.

molsonexpert said:
your code suggests 'if text46 is blank, then make it now()'

there's a big difference between null and blank. try changing it to if
[text46] is null then...

--
steve.


Vadimbar said:
Hello I have two if then statements.
1. If [Text40] = "" Then
[Text40] = Now()
End If
works just fine I can step through it no problem.

2.If [Text46] = "" Then
[Text46] = Now()
End If
Always bypasses the then statement and goes directly to End if. Even
though
the value is null. What could be causing this?
The fields are the same type in every way. Any ideas?

Thank you
Vadimbar
 
K

Klatuu

Or to be concise:

1. Me.Text40 = Nz(Me.Text40, Now())

2. Me.Text49 = Nz(Me.text40, Now())

--
Dave Hargis, Microsoft Access MVP


Vadimbar said:
Thank you.

molsonexpert said:
your code suggests 'if text46 is blank, then make it now()'

there's a big difference between null and blank. try changing it to if
[text46] is null then...

--
steve.


Vadimbar said:
Hello I have two if then statements.
1. If [Text40] = "" Then
[Text40] = Now()
End If
works just fine I can step through it no problem.

2.If [Text46] = "" Then
[Text46] = Now()
End If
Always bypasses the then statement and goes directly to End if. Even
though
the value is null. What could be causing this?
The fields are the same type in every way. Any ideas?

Thank you
Vadimbar
 
Top