If - Then - Else

Ali Edwards

Registered User.
Local time
Today, 23:05
Joined
Apr 19, 2001
Messages
68
Hi!

I am trying to evaluate whether several text boxes are null so that certain labels are visible.

If I want to do this with one text box I am using:

If isnull me!textbox1 then
me!label1.visible=true
else
me!label1.visible=false
end if

How can I check if more than one text box isnull?

I kind of want to do:

if isnull ([me!text box1] OR [me!textbox2] OR [me!textbox3]) then
me!label1.visible=true
else
me!label1.visible=false
end if

But it doesn't work no matter how many variations of brackets I use!! Can you use 'Or' or 'AND'? in If-then-else statements?


Many thanks

Ali
 
Try:

if isnull ([me!text box1]) OR isnull ([me!textbox2]) OR isnull ([me!textbox3]) then
 
If you like to catch all the textboxces that are empty and make their labels invisible, you can use this single code

Set textboxes to the following properties to avoid having empty spaces in between visible labels/textboxes

Can Grow yes
Can Shrink yes

Set the following code to the On Format property of the Detail section of the report

Dim ctl As Control
On Error Resume Next
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If Me(ctl.Name) = "" Or IsNull(Me(ctl.Name)) Then
Me(ctl.Name).Visible = False
Me(ctl.Name & " Label").Visible = False
Else
Me(ctl.Name).Visible = True
Me(ctl.Name & " Label").Visible = True
End If
End If
Next

Let me know how it worked
Marcel
 
I'm sorry - I should have explained that this is in a form not a report, so there is no On Format.


The line- if isnull ([me!text box1]) OR isnull ([me!textbox2]) OR isnull ([me!textbox3]) then
didn't work but also didn't throw up any errors which is at least an improvement! It only worked if all txtboxes were null.

Thanks again!!

Ali
 
Sorry,

Try

if isnull (me("text box1")) OR isnull (me("textbox2")) OR isnull (me("textbox3")) then

If referring from code or:

if isnull ([text box1]) OR isnull ([textbox2]) OR isnull [textbox3] then

if referencing controls from a control on the form

Hope it helps.

Ian
 
Ian

That did it!!

Thank you very much for your help.

Regards
Ali
 

Users who are viewing this thread

Back
Top Bottom