title: UserForm populate listbox with criteria
body: <p>I have a database with five columns in a different workbook called db.xls : 
  <strong>userid - date - name - subject - comments</strong></p>
  
  <p>I fill this with a data entry form (works fine). The problem is in a UserForm, I need to retrieve specific entries on a specific criteria in a listbox. I need to put the <strong>name</strong> AND <strong>subject</strong> in two textboxes or dropdown lists and with these two criteria populate a listbox, in a ascending order by <strong>date + the subject</strong> and when I click on any listbox entries, it lookup and give me the comment that goes with that line in textbox.</p>
  
  <p><strong>CODE :</strong> </p>
  
  <pre><code>Private Sub searchbutton_Click()
  
  Dim nwb As Workbook
  
  Application.ScreenUpdating = False
  
  Set nwb = Workbooks.Open("C:\db.xls", _
  False, True)
  
  txtsubject.Text = ""
  
  Set xSht = nwb.Sheets("notes")
      Lastrow = xSht.Range("C" &amp; Rows.Count).End(xlUp).Row
      strSearch = txtname.Text
                  Set aCell = xSht.Range("C1:C" &amp; Lastrow).Find(What:=strSearch, LookIn:=xlFormulas, _
  LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
  MatchCase:=False, SearchFormat:=False)
  
    If Not aCell Is Nothing And txtsubject.Value = "" Then
       GoTo refvalid
   Else
  MsgBox "no entries for " &amp; txtname.Value &amp; ". ", Title:="result of search"
      End If
  Exit Sub
  refvalid:
  
  row_number = 0
  ListBox1.Clear
  Do
  DoEvents
  row_number = row_number + 1
  item_in_review = nwb.Sheets("notes").Range("C" &amp; row_number)
  If item_in_review = txtname.Text Then
  txtsubject.Text = nwb.Sheets("notes").Range("A" &amp; row_number)
  'concatenated date + subject in column F
  ListBox1.AddItem nwb.Sheets("notes").Range("F" &amp; row_number) 
  
  End If
  Loop Until item_in_review = ""
  'in module, sortlistbox to order then ascending
  Run "SortListBox", ListBox1, 0, 1, 1
  
  nwb.Close False ' close the source workbook without saving changes
  Set nwb = Nothing
  Application.ScreenUpdating = True
  With ListBox1
  
  .ColumnCount = 5
  .MultiSelect = fmMultiSelectSingle
  .TextColumn = 1
  .BoundColumn = 1
  If ListBox1.Value &lt;&gt; "" Then
  TextBox35.Value = " [" &amp; ListBox1.Text &amp; "] : " &amp; ListBox1.Value
  End If
  
  End With
  End Sub
  
  '====================================================
  
  Private Sub ListBox1_Click()
  If ListBox1.Value &lt;&gt; "" Then
  TextBox5.Value = " [" &amp; ListBox1.Text &amp; "] : " &amp; ListBox1.Value
  End If
  
  End Sub
  </code></pre>