Cannot get form to show field based on value of another field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BobbyD1120
    New Member
    • Mar 2010
    • 2

    Cannot get form to show field based on value of another field

    I have created a inventory tracking database and I want to show/hide certain fields based on the device category. The deviceCategory field is a lookup field to a table that lists all the different type of devices to include PC, Printer, Network....

    I want it so that when you select a certain category device you get the fields related to the device. For example if you get PC I want to show the fields for Model, Service Tag, RAM, ....

    For testing Im only working with showing the model field. I currently have the model field visible set to "No" and then in the deviceCategory I set an afterUpdate event to

    Code:
    Private Sub test_AfterUpdate()
    If deviceCategory = "test" Then
    deviceModel.Visable = True
    End Sub
    According to http://bytes.com/topic/access/answers/854100-how-do-i-hide-form-field-only-show-based-value-another-form-field it should work. What am I doing wrong? Thanks!
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    You have your code in the AfterUpdate event of a Control named test and you have no End If. It needs to be in the deviceCategory_ AfterUpdate event, and really should read:
    Code:
    Private Sub deviceCategory_AfterUpdate()
     If Me.deviceCategory = "test" Then
       deviceModel.Visable = True
     End If
    End Sub

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • BobbyD1120
      New Member
      • Mar 2010
      • 2

      #3
      thank you for the reply. My original post had the wrong info from my test db. I corrected it as follows:
      Code:
      Private Sub Category_AfterUpdate()
      If Me.Category = "Laptop" Then
       Model.Visible = True
      End If
      End Sub
      OK, it is working when I have the Category set up as a text field. However, category is a drop down list from which to select the value. How do I get it to update this way? When I have a drop down list it does not work w/ afterUpdate?

      Also, it appears that when Laptop is listed in Category it now shows the Model field over every record. I want it to only show on the records for which category is listed as laptop, still hide on all other records.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32656

        #4
        Originally posted by BobbyD1120
        Also, it appears that when Laptop is listed in Category it now shows the Model field over every record. I want it to only show on the records for which category is listed as laptop, still hide on all other records.
        See Why Values in Unbound Form Controls do not Persist for why that won't work. You would need to look at creating the condition in the underlying record source. Even then I doubt you could hide the control exactly.

        Comment

        Working...