If Statement!

D

Dave Elliott

I just need if ([Additional Sample]) value is less than 1 (zero) then
next code following to run
right now the Additional Sample control shows by default 0 and default value
is set to true
If it has a zero in it then the code does not work


If IsNull([Additional Sample]) Then ' less than 1 or equals zero
[Sample #1 Date].Visible = False
[Label100].Visible = False
End If
 
B

BruceM

How about:

If Me.AdditionalSample < 1 Then
Me.Sample #1 Date.Visible = False
Me.Label100.Visible = False
End If

That first line could be:

If IsNull(Me.AdditionalSample) or Me.AdditionalSample < 1 Then

I would leave special symbols such as # out of field and control names.
 
K

Klatuu

You are testing for Null. It will never be true unless [Additional Sample]
contains a null vaule. Here is the correction:

If Nz([Additional Sample],0) <=0 Then ' less than 1 or equals zero
[Sample #1 Date].Visible = False
[Label100].Visible = False
End If
 
K

Klatuu

See my post, Bruce. If you want 0 and check for < 1, then .0001 would
evaluate to false. Better is <= 0

BruceM said:
How about:

If Me.AdditionalSample < 1 Then
Me.Sample #1 Date.Visible = False
Me.Label100.Visible = False
End If

That first line could be:

If IsNull(Me.AdditionalSample) or Me.AdditionalSample < 1 Then

I would leave special symbols such as # out of field and control names.


Dave Elliott said:
I just need if ([Additional Sample]) value is less than 1 (zero) then
next code following to run
right now the Additional Sample control shows by default 0 and default
value
is set to true
If it has a zero in it then the code does not work


If IsNull([Additional Sample]) Then ' less than 1 or equals zero
[Sample #1 Date].Visible = False
[Label100].Visible = False
End If
 
D

Dave Elliott

This code still errors out , WhY ?
If Nz([Me.AdditionalSample2], 0) <= 0 Then

It says it has no value

Klatuu said:
You are testing for Null. It will never be true unless [Additional
Sample]
contains a null vaule. Here is the correction:

If Nz([Additional Sample],0) <=0 Then ' less than 1 or equals zero
[Sample #1 Date].Visible = False
[Label100].Visible = False
End If


Dave Elliott said:
I just need if ([Additional Sample]) value is less than 1 (zero)
then
next code following to run
right now the Additional Sample control shows by default 0 and default
value
is set to true
If it has a zero in it then the code does not work


If IsNull([Additional Sample]) Then ' less than 1 or equals zero
[Sample #1 Date].Visible = False
[Label100].Visible = False
End If
 
D

Dave Elliott

This wont work? It says expression has no value ???
If [additionalsample2] is greater than 0 then fields are to be visible!

Me![AdditionalSample2].Visible = (Me![AdditionalSample2] > 0) ' Number
Me![Sample2Dte].Visible = (Me![AddionalSample2] > 0) ' Date Field
Me![Label113].Visible = (Me![AddionalSample2] > 0) ' Label
 
Top