Results 1 to 5 of 5
  1. #1
    RunTime91 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2014
    Posts
    281

    ListBox Loop not working

    I'm trying to use the ListBox.ControlTipText to display text from a very long entry in a Listbox.



    I've looked at previous versions of Loops just like this and they seem to work just fine - This one, however, does not work at all.

    Here are a couple versions I've tried - the row selected in the Listbox is row 6
    What happens is the Loop never connects to the 'Then' statement -
    However, if I manually place the code on that line - the ControlTipText displays the correct text.
    Clearly I'm not seeing something ??

    Thank You!!!
    Code:
    Private Sub LstRePubQs_Click()
    
      Dim i As Integer
      Dim str As String
      For i = 0 To Me.LstRePubQs.ListCount - 1
          If (Me.LstRePubQs.Selected(i) = True) Then
              str = Me.LstRePubQs.Column(1, i)
              Exit For
          End If
      Next
      Me.LstRePubQs.ControlTipText = str
      Debug.Print str
    
    End Sub
    


    Code:
    Private Sub LstRePubQs_Click()
    
      Dim i As Integer
      Dim str As String
      For i = 0 To Me.LstRePubQs.ListCount - 1
          If Me.LstRePubQs.Selected(i) Then
              str = Me.LstRePubQs.Column(1, i)
              Exit For
          End If
      Next
      Me.LstRePubQs.ControlTipText = str
      Debug.Print str
    
    End Sub

  2. #2
    RunTime91 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2014
    Posts
    281
    Update ~

    Okay - not sure why, but if I place the same code as the second example above on a CommandButton click event - it works perfectly...

    Now, one thing I did notice when I was stepping through the code the ListBox goes blank until End Sub then it re-populates

    Any ideas?

    I would like for the code to work when the end user clicks on the row which they can't read the whole entry because it is too long

    Thanks

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is the listbox multiselect? If not, I wouldn't bother looping, just set the value in the after update event. You might consider a textbox too, though obviously that would take up some space.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    As PBaldy suggests, all you need in afterupdate is

    Me.LstRePubQs.ControlTipText =
    Me.LstRePubQs.Column(1)

  5. #5
    RunTime91 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2014
    Posts
    281
    Paul & Moke ~

    Thank You!!

    Seeing the solution makes me just shake my head -

    I honestly wish there was a way I could improve my ability to 'think' like a developer...

    But then I suppose if I could do that then I wouldn't get to come here and bug you guys - lol

    Thanks again you two! - Have a Great Weekend!

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

Similar Threads

  1. Nested Loop Not working correctly in Subform
    By canela123 in forum Programming
    Replies: 4
    Last Post: 11-25-2017, 01:48 AM
  2. Replies: 25
    Last Post: 11-22-2017, 03:18 PM
  3. Loop trough listbox to update table
    By mari_hitz in forum Programming
    Replies: 4
    Last Post: 04-21-2014, 07:16 AM
  4. Replies: 5
    Last Post: 12-21-2013, 06:26 PM
  5. Replies: 6
    Last Post: 02-19-2012, 03:58 PM

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