If statement with multiple criteria

Pooks_35

Registered User.
Local time
Today, 10:34
Joined
Mar 14, 2013
Messages
54
Good afternoon,
I'm trying to create a report that does the following:
If the term "Other" is selected in the Time1 field, then the Time1 field will not be visible, but the field Other1 field will be visible and if the term "Other" is not selected in Time1 field, then the Time1 field will be visible and the Other1 field will not be. This is what I have for VBA code, but it is not working. Can anyone help me understand what I am doing wrong? Thanks!

If Not IsNull(Me.Time1) Then
If Me.Time1 = "Other" Then
Me.Time1.Visible = False
Else
Me.Time1.Visible = True
End If
Else
If Me.Time1 <> "Other" Then
Me.Other1.Visible = False
Else
Me.Other1.Visible = True
End If
End If
 
Me.Time1.Visible = Me.Time1 <> "Other"
Me.Other1.Visible = Me.Time1 = "Other"

You would need to make sure this is in the after update event of Time1.
 
Hi TJPoorman,
This is actually in a report so I won't be updating anything, just running a report based off of data I enter into a form.
 
Presuming you're using Preview or Print views, code like that would go in the format event of the section containing the textboxes (presumably the detail section).
 
Hi PBaldy,
That's helpful! But now the question is what is the correct code I use? The one I posted or the one posted by Poorman?
Thanks
 
I haven't tried to follow yours, but probably either. TJ's uses a shortcut with what's called Boolean logic. The second bit, Me.Time1 <> "Other", will evaluate to True or False, thus setting the property in the first bit. It avoids the If/Then block by placing the logic in the single line. It works perfectly well, but can be hard to understand at first.
 
It works, but I have several fields that need to do that Time1, Time2, Time3, etc. I get a Compile error: Method or data member not found.

Me.Time1.Visible = Me.Time1 <> "Other"
Me.Other1.Visible = Me.Time1 = "Other"

Me.Time2.Visible = Me.Time2 <> "Other"
Me.Other2.Visible = Me.Time2 = "Other"
 
Last edited:

Users who are viewing this thread

Back
Top Bottom