Trying to make fields not visible on a form is certain criteria exists

I have a form with two fields that I want to NOT be visible if certain criteria exists.  Here is my code which is not working...

    If Me.txtType = "FG" Or "A" Or "WT" Then
        Me.txtJobN.Visible = False
        Me.cboWH.Visible = False
    End If

    If Me.txtType = "P" Or "S" Then
        Me.txtJobN.Visible = True
        Me.cboWH.Visible = True
    End If

Can someone see what I'm doing wrong?

--Steve
SteveL13Asked:
Who is Participating?
 
mbizupCommented:
Correction to the if-then-else block, and you should also specify a catch-all condition in case neither criteria holds true:

    If Me.txtType = "FG" Or  Me.txtType = "A" Or  Me.txtType = "WT" Then
        Me.txtJobN.Visible = False
        Me.cboWH.Visible = False

    elseIf Me.txtType = "P" Or Me.txtType ="S" Then
        Me.txtJobN.Visible = True
        Me.cboWH.Visible = True
    Else
         ' neither of the above are true
    End If

0
 
mbizupCommented:
Try this:

SELECT Case Me.txtType
     case "FG","A", "WT"
        Me.txtJobN.Visible = False
        Me.cboWH.Visible = False
    Case "P", "S"
        Me.txtJobN.Visible = true
        Me.cboWH.Visible = true
    case else
        ' etc
end select
0
 
mbizupCommented:
This will also work:

    If Me.txtType = "FG" Or "A" Or "WT" Then
        Me.txtJobN.Visible = False
        Me.cboWH.Visible = False

    elseIf Me.txtType = "P" Or "S" Then
        Me.txtJobN.Visible = True
        Me.cboWH.Visible = True
    End If

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
How about this:

   Me.txtTest.Visible = Switch(Me.txtTest = "FG" Or "A" Or "WT", False, Me.txtTest = "P" Or "S", True)

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
With else case


Me.txtTest.Visible = Switch(Me.txtTest = "FG" Or "A" Or "WT", False, Me.txtTest = "P" Or "S", True,1=1,False)

mx
0
 
SteveL13Author Commented:
So far none of the suggestions are working.  No matter what I do the fields remain visible.
0
 
mbizupCommented:
Where is your code located?
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Then something else is going on ...

Where exactly do you have the code?

mx
0
 
SteveL13Author Commented:
I've tried after update and before update event of the txtType field.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
One place for sure the code s/b is on the Form Current event ... so that when you navigation through existing records, the proper visibility is set.

mx
0
 
mbizupCommented:
Make sure that the code is 'connected' to the event.

Click the "..." next to AfterUpdate to make sure.

Also, try it behind the click event of a command button.
0
 
SteveL13Author Commented:
I understand needing it in the on current evene tof the form but I also need it in the after update event of the field for new records, correct?
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"I've tried after update and before update event of the txtType field."

It would need to be in the AfterUpdate event, not the BU

mx
0
 
mbizupCommented:
<after update event of the field for new records, correct? >

Yes.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"I understand needing it in the on current evene tof the form but I also need it in the after update event of the field for new records, correct?"
Definitely.

mx
0
 
mbizupCommented:
Jsut FYI, my suggestion of using a command button click event is simply debugging - to verify that the code works independent of other things on your form.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
This won't help your issue right now, but as a side note keep this in mind:

In most cases, users find "magically disappearing fields" to be somewhat distracting. If the fields are to be used by ALL users, then it's often best to disable them instead of hiding them. If the fields are to be used only by certain users - for example, the Managers group should see the controls, but "regular" users should not - then it would make sense to hid them.
0
 
mbizupCommented:
Excellent point!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.