?
Solved

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

Posted on 2011-10-10
18
Medium Priority
?
252 Views
Last Modified: 2013-11-05
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
0
Comment
Question by:SteveL13
  • 8
  • 6
  • 3
  • +1
18 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 36945090
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
 
LVL 61

Expert Comment

by:mbizup
ID: 36945097
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
 
LVL 61

Accepted Solution

by:
mbizup earned 1000 total points
ID: 36945118
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 75
ID: 36945153
How about this:

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

mx
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 1000 total points
ID: 36945159
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
 

Author Comment

by:SteveL13
ID: 36945179
So far none of the suggestions are working.  No matter what I do the fields remain visible.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36945191
Where is your code located?
0
 
LVL 75
ID: 36945198
Then something else is going on ...

Where exactly do you have the code?

mx
0
 

Author Comment

by:SteveL13
ID: 36945203
I've tried after update and before update event of the txtType field.
0
 
LVL 75
ID: 36945210
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
 
LVL 61

Expert Comment

by:mbizup
ID: 36945215
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
 

Author Comment

by:SteveL13
ID: 36945222
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
 
LVL 75
ID: 36945225
"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
 
LVL 61

Expert Comment

by:mbizup
ID: 36945229
<after update event of the field for new records, correct? >

Yes.
0
 
LVL 75
ID: 36945239
"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
 
LVL 61

Expert Comment

by:mbizup
ID: 36945240
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
 
LVL 85
ID: 36945393
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
 
LVL 61

Expert Comment

by:mbizup
ID: 36945439
Excellent point!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question