If then Statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
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...
 
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
 
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
 
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
 
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
 

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

Back
Top