title: How can i call the below function to populate my access form list control
body: <p>I need to populate the access form list box from a access table. </p>
  
  <p>Below is the code which I copy-pasted on button click event:</p>
  
  <pre><code>Public Sub PopulateLBWithData(DBPath As String, _
  TableName As String, FieldName As String, _
  oListControl As Object,Optional Distinct As Boolean = False, _
  Optional OrderBy As String)
  
  ''#PURPOSE: Populate a list box, combo box
  ''#or control with similar interface with data
  ''#from one field in a Access Database table
  
  ''#Parameters: DBPath: FullPath to Database
  ''#TableName: The Name of the Table
  ''#FieldName: Name of the Field
  ''#Distinct: Optional -- True if you want distinct value
  ''#Order By:  Optional -- Field to Order Results by
  
  ''#Must have reference to DAO in your project
  
  Dim sSQL As String
  Dim db As DAO.Database
  Dim rs As DAO.Recordset
  Dim td As DAO.TableDef
  Dim f As DAO.Field
  
  Dim sTest As String
  Dim bIsNumeric As Boolean
  Dim i As Integer
  
  On Error Resume Next
  
  ''#validate all parameters
  
  oListControl.AddItem "a"
  oListControl.Clear
  If Err.Number &gt; 0 Then Exit Sub
  
  sTest = Dir(DBPath)
  If sTest = "" Then Exit Sub
  
  Set db = Workspaces(0).OpenDatabase(DBPath)
  If Err.Number &gt; 0 Then Exit Sub
  
  Set td = db.TableDefs(TableName)
  If Err.Number &gt; 0 Then
      db.Close
      Exit Sub
  End If
  
  Set f = td.Fields(FieldName)
      If Err.Number &gt; 0 Then
          db.Close
          Exit Sub
      End If
  
  If Len(OrderBy) Then
      Set f = td.Fields(OrderBy)
      If Err.Number &gt; 0 Then
          db.Close
          Exit Sub
      End If
  End If
  
  sSQL = "SELECT "
  If Distinct Then sSQL = sSQL &amp; "DISTINCT "
  sSQL = sSQL &amp; "[" &amp; FieldName &amp; "] FROM [" &amp; TableName &amp; "]"
  
  If OrderBy &lt;&gt; "" Then sSQL = sSQL &amp; " ORDER BY " &amp; OrderBy
  
  Set rs = db.OpenRecordSet(sSQL, dbOpenForwardOnly)
  
  With rs
      Do While Not .EOF
          oListControl.AddItem rs(FieldName)
          .MoveNext
      Loop
      .Close
  End With
  
  db.Close
  End Sub
  </code></pre>
  
  <p>But this function need arguments according to the VBA conventions.</p>
  
  <p>Please help me how i can call this function to populate my vba form list box from the same access table?</p>