Results 1 to 4 of 4
  1. #1
    nichmeg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Oct 2011
    Posts
    31

    Visible text boxes when combo box choice selected

    I am new at visual basic and am trying some new things with it.

    I have created a few combo boxes in my form with yes/no choices. The text input boxes are not visible unless the yes is selected and then they show up.

    Code that I have for this: vb Code:

    1. '--------------------------------------------------------------------
    2. Private Sub Knox_Box_AfterUpdate()
    3. If Me.Knox_Box = "Yes" Then Me.Knox_Box_Location.Visible = True Else Me.Knox_Box_Location.Visible = False
    4. End Sub
    5. '---------------------------------------------------------------------
    6. Private Sub Knox_Box_BeforeUpdate(Cancel As Integer)
    7. If Me.Knox_Box = "yes" Then
    8. If Trim(Nz(Me.Knox_Box_Location)) = "" Then
    9. MsgBox "Knox Box Location is required when Knox Box is Yes."
    10. Cancel = False
    11. End If
    12. End If
    13. End Sub
    14. '---------------------------------------------------------------------




    The problem I am having (and don't know if it feasible or not) is that for another combo box selection I have 3 choices: yes/no/partial. I have 2 text input boxes referencing different fields in the table for data storage. I want it to show the one box if yes is selected, both boxes if partial is selected, and none if no is selected.

    Here is what i have so far, but have tried numerous methods. The best I get is for the 1 box to open when yes is selected, none to show when no is selected, and none to show when partial is selected which is not what I am looking to do. The message box works fine for yes, no, and partial.

    problem code: vb Code:

    1. '-------------------------------------------------------------------------
    2. Private Sub Sprinkler_AfterUpdate()
    3. If Me.Sprinkler = "Yes" Then Me.FDC_Location.Visible = True
    4. If Me.Sprinkler = "No" Then Me.FDC_Location.Visible = False
    5. If Me.Sprinkler = "Partial" Then
    6. Me.FDC_Location.Visible = True And Me.Partial_Sprinkle.Visible = True
    7. Else
    8. Me.FDC_Location.Visible = False And Me.Partial_Sprinkle.Visible = False
    9. End If
    10. End Sub
    11. -------------------------------------------------------------------------
    12. Private Sub Sprinkler_BeforeUpdate(Cancel As Integer)
    13. If Me.Sprinkler = "yes" Then
    14. If Trim(Nz(Me.FDC_Location)) = "" Then
    15. MsgBox "FDC Location is required when Sprinkler is Present."
    16. Cancel = False
    17. End If
    18. End If
    19. If Me.Sprinkler = "Partial" Then
    20. If Trim(Nz(Me.FDC_Location)) = "" Then
    21. MsgBox "Box #1) FDC Location is required when Sprinkler is present." & vbCrLf & "Box #2) List Locations covered by Sprinkler."
    22. Cancel = False
    23. End If
    24. End If
    25. End Sub
    26. '-----------------------------------------------------------------------







    Any help would be appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The problem with your code is that the test for "Partial" runs no matter what, so the If or Else for that will determine the visibility, irregardless of whether one of the other tests was true. You either want Select/Case or ElseIf so that code will drop out once a test is met.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    nichmeg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Oct 2011
    Posts
    31
    I ended up doing like you suggested, and ended up like this:

    Private Sub Sprinkler_AfterUpdate()

    Select Case Me.Sprinkler
    Case "Yes"
    Me.FDC_Location.Visible = True
    Case "Partial"
    Me.FDC_Location.Visible = True
    Me.Partial_Sprinkle.Visible = True
    Case Else
    Me.FDC_Location.Visible = False
    Me.Partial_Sprinkle.Visible = False
    End Select

    End Sub

    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, glad it worked for you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 06-04-2014, 10:45 AM
  2. Creating a Form with 2 combo boxes and a text box
    By smorris4804 in forum Access
    Replies: 1
    Last Post: 06-17-2011, 02:06 PM
  3. populate boxes based on combo box choice
    By Mattm1958 in forum Forms
    Replies: 13
    Last Post: 08-30-2010, 02:09 PM
  4. Combo Boxes Visible/Invisible
    By Rick West in forum Forms
    Replies: 2
    Last Post: 07-06-2010, 09:41 AM
  5. Replies: 1
    Last Post: 03-27-2010, 06:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums