Results 1 to 8 of 8
  1. #1
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272

    Combo list selection to activate a field

    I have a form with one combo list called “bap”


    and another textbox called “date_bap.

    The combo list contain (Yes and No) options.

    I will like to set it up so that when ever I select yes in the combo list, the textbox “date_bap” will appear but when ever I select No in the drop down, the textbox “date_bap” will be hidden

    How will I do that?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    In the AfterUpdate event of the combo, set the date_bap control visible property to True or False depending on the combo value.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by Welshgasman View Post
    In the AfterUpdate event of the combo, set the date_bap control visible property to True or False depending on the combo value.
    Have tried a couple of codes online using the after update
    Can you assist me because what I tried isn’t working

  4. #4
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not sure if you mean a combo box or a list box, but I guess it doesn't matter. The end result eill be the dame.

    Set the visible property of the text box "date_bap" to "No".

    Add the following code to the combo box after update event.
    Code:
    Private Sub bap_AfterUpdate()
        If Nz(Me.bap, "No") = "Yes" Then
            Me.date_bap.Visible = True
        Else
            Me.date_bap = vbNullString   ' clear any existing value
            Me.date_bap.Visible = False
        End If
    End Sub
    Then you also need to add code to the form current event:
    Code:
    Private Sub Form_Current()
        Me.date_bap.Visible = (Nz(Me.bap, "No") = "Yes")
    End Sub
    The top two lines of the module (every module) should be
    Code:
    Option Compare Database
    Option Explicit

    Edit: Oops......Welshgasman beat me.....

  5. #5
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by ssanfu View Post
    Not sure if you mean a combo box or a list box, but I guess it doesn't matter. The end result eill be the dame.

    Set the visible property of the text box "date_bap" to "No".

    Add the following code to the combo box after update event.
    Code:
    Private Sub bap_AfterUpdate()
        If Nz(Me.bap, "No") = "Yes" Then
            Me.date_bap.Visible = True
        Else
            Me.date_bap = vbNullString   ' clear any existing value
            Me.date_bap.Visible = False
        End If
    End Sub
    Then you also need to add code to the form current event:
    Code:
    Private Sub Form_Current()
        Me.date_bap.Visible = (Nz(Me.bap, "No") = "Yes")
    End Sub
    The top two lines of the module (every module) should be
    Code:
    Option Compare Database
    Option Explicit

    Edit: Oops......Welshgasman beat me.....
    So I will add

    Option Compare Database
    Option Explicit

    at the top of all the codes I guess

  6. #6
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by ssanfu View Post
    Not sure if you mean a combo box or a list box, but I guess it doesn't matter. The end result eill be the dame.

    Set the visible property of the text box "date_bap" to "No".

    Add the following code to the combo box after update event.
    Code:
    Private Sub bap_AfterUpdate()
        If Nz(Me.bap, "No") = "Yes" Then
            Me.date_bap.Visible = True
        Else
            Me.date_bap = vbNullString   ' clear any existing value
            Me.date_bap.Visible = False
        End If
    End Sub
    Then you also need to add code to the form current event:
    Code:
    Private Sub Form_Current()
        Me.date_bap.Visible = (Nz(Me.bap, "No") = "Yes")
    End Sub
    The top two lines of the module (every module) should be
    Code:
    Option Compare Database
    Option Explicit

    Edit: Oops......Welshgasman beat me.....
    I tired and it worked
    Thanks so much man
    You the best

  7. #7
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    For existing modules, yes you should manually add the "Option Explicit" line.


    You can set an option to automatically add the line for NEW modules. In the IDE, click on TOOLS/OPTIONS. On the Editor tab, select (check) "Require Variable Declaration".

  8. #8
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Great.....happy to help

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

Similar Threads

  1. Replies: 2
    Last Post: 10-29-2019, 02:24 PM
  2. Replies: 10
    Last Post: 08-19-2018, 01:22 PM
  3. Replies: 3
    Last Post: 06-16-2018, 11:12 PM
  4. Replies: 1
    Last Post: 03-27-2012, 07:10 AM
  5. Filter List box from combo box selection
    By thart21 in forum Forms
    Replies: 3
    Last Post: 11-09-2011, 12:00 PM

Tags for this Thread

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