Results 1 to 4 of 4
  1. #1
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149

    cannot show record from listbox

    I create a textbox "PhoneSearch", a listbox "PhoneList", and 3 labels "Name", "Phone" and "Address".


    when enter a phone no. in PhoneSearch, then show the result in PhoneList.
    if only one record is found, show the corresponding values into the 3 labels.
    but in debug mode, one record is found, it call PhoneList_Click,
    but Me.PhoneList.Column(0), Column(1), Column(2) all are null values.
    what wrong in my coding?

    Code:
    Private Sub PhoneSearch_LostFocus()
        Me.PhoneList.RowSource = "SELECT Name,Phone,Address FROM Contacts WHERE Phone LIKE '*" & Me.PhoneSearch & "*'"
        If Nz(DCount("Phone", "Contacts", "Phone LIKE '*" & Me.PhoneSearch & "*'"), 0) = 1 Then
            Me.PhoneList.Requery
            PhoneList_Click
        End If
    End Sub
    Private Sub PhoneList_Click()
        Me.Name.Caption = Me.PhoneList.Column(0)
        Me.Phone.Caption = Me.PhoneList.Column(1)
        Me.Address.Caption = Me.PhoneList.Column(2)
    
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Instead of VBA setting label caption, could have expression in textbox referencing listbox columns. But why do you need to show this data in labels or textboxes since the listbox already displays this info?

    Did you step debug?

    Code looks fine so hard to say why no data shows without knowing your db. You could provide it for analysis. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    Of course, I step the debug.
    Actually, the listbox rowsource retrieves other data from the Contacts table.
    The listbox just show the first 3 data, the rest will be shown on the labels if click on the listbox.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I am confused. SQL shows only 3 fields. How could 'other' data show?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 8
    Last Post: 06-10-2021, 09:15 PM
  2. Replies: 4
    Last Post: 06-04-2021, 05:47 AM
  3. Replies: 15
    Last Post: 08-30-2020, 07:11 PM
  4. Replies: 1
    Last Post: 05-21-2017, 12:31 AM
  5. Replies: 1
    Last Post: 09-10-2012, 11:21 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