Results 1 to 5 of 5
  1. #1
    cbrsix is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    215

    Listbox and Subform

    I have a listbox that updates its records when a textbox on the form is changed.
    Code:
    Private Sub ClientSearch_Change()
        Dim sql As String
        
        'if you want to match any part of the string then add wildcard (*) before the FilterBy.Text, too:
        sql = "SELECT ClientNameList, ClientName FROM ClientList WHERE ClientName Like '*" & Me.ClientSearch.Text & "*' ORDER BY ClientName"
        
        Me.ClientNameList.RowSource = sql
    End Sub
    Private Sub ClientSearch_Click()
    Me.ClientSearch = ""
    Me.ClientSearch.FontItalic = False
    End Sub
     
    Private Sub Form_Load()
    Me.ClientSearch = "Search..."
    Me.ClientSearch.FontItalic = True
    End Sub
    I have also have a subform that updates to the selected client from the listbox. This works fine up until I narrow down the listbox with the above code. Once I narrow the list down, when I select a record in the listbox to display in the subform, it doesn't update the subform at all.



    On the subform, the Masterlink field is ClientNameList and the Childlink field is ClientID

  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,652
    Perhaps because ClientID isn't in the row source? Make sure that matches whatever the row source is before it's changed with this code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cbrsix is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    215
    Thanks, I was able to figure it out.

  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,652
    Posting your solution could help later users searching for help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    cbrsix is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    215
    yes it would. here it is.
    Code:
    Private Sub ClientSearch_Change()
        Dim sql As String
        If Me.ClientSearch.Text = "" Then
            sql = "SELECT [ClientList].[ClientID], [ClientList].[ClientName] FROM ClientList ORDER BY [ClientName]"
         Else
            sql = "SELECT [ClientList].[ClientID], [ClientList].[ClientName] FROM ClientList WHERE ClientName Like '*" & Me.ClientSearch.Text & "*' ORDER BY [ClientName]"
        End If
        
        Me.ClientNameList.RowSource = sql
        
    End Sub

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

Similar Threads

  1. listbox on subform
    By moona in forum Forms
    Replies: 3
    Last Post: 07-23-2013, 12:19 PM
  2. Replies: 4
    Last Post: 11-16-2012, 02:43 AM
  3. Replies: 5
    Last Post: 03-23-2012, 10:54 AM
  4. Subform to show records of Listbox
    By gbmarlysis in forum Forms
    Replies: 5
    Last Post: 02-27-2012, 04:03 PM
  5. Replies: 1
    Last Post: 03-15-2011, 03:53 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