Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2010
    Posts
    2

    Unanswered: Click event in Access Forms

    I am trying to register a click event. I have a listbox which is populated using a query. Now when I select a particular item in that list box. I want a textbox to be visible at the same time.


    I hope I am clear.

    Thanks
    MMike

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    This assumes that your Listbox has the Multi-Select Property set to None. Doing it otherwise would take entirely different code, as Listboxes only have a Value Property if Multi-Select is set to No.

    You'll have to replace YourListBoxName and YourTextBoxName with your actual names and TargetValue with the actual value of your bound field in the Listbox that you want to trigger the visibility of the textbox.

    Code:
    Private Sub Form_Current()
    If Me.YourListBoxName.Value = "TargetValue" Then
      Me.YourTextBoxName.Visible = True
    Else
      Me.YourTextBoxName.Visible = False
    End If
    End Sub
    
    Private Sub YourListBoxName_AfterUpdate()
    If Me.YourListBoxName.Value = "TargetValue" Then
      Me.YourTextBoxName.Visible = True
    Else
      Me.YourTextBoxName.Visible = False
    End If
    End Sub
    Note that the Listbox also has to be bound to a field in the underlying record/table in order for the visibility/invisibility to persist appropriately as you move from record to record.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Jun 2010
    Posts
    2

    Multiselect > Simple

    Ya I am selecting multiple values in that listbox and I want to disply the textbox if a particular value out of that multiple selection is selected.

    Thanks for your code and help!!
    Mike

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    That will require different code then, as I indicated! I'm headed out the door for a family function and have no idea when I'll get back, but I'll try to post something later today or tomorrow. Maybe someone else here can give you an example for looping thru multi-selections.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Sorry for taking so long to get back to you! "She who must be obeyed" had some health problems and we spent all day at medical facilities yesterday. This should work for Comboboxes with Multi-Select Property set to something other than None.
    Code:
    Private Sub YourListBoxName_AfterUpdate()
    Dim valSelect As Variant
     
    For Each valSelect In Me.YourListBoxName.ItemsSelected
    
     If Me.YourListBoxName.ItemData(valSelect) = "TargetValue" Then
      Me.YourTextBoxName.Visible = True
      Exit Sub
     Else
      Me.YourTextBoxName.Visible = False
     End If
     
    Next valSelect
    
    End Sub
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •