title: "Object variable or With block variable not set" runtime error in VB6
body: <p>I've got a problem with VB6. I have a form with several ComboBox objects on it. I wish to populate the ComboBoxes via a function that takes a SQL query as a parameter. So the code looks like this</p>
  
  <pre><code>Private Function FillComboBoxFromMDB(ByVal sDBName As String, _
                                       ByVal sSQL As String) As ComboBox
      '/*
      ' * Execute SQL in MDB and fill the ComboBox with the results
      ' * Returns filled ComboBox
      ' */
      Dim DB As Database
      Dim DBRecordset As Recordset
  
      On Error GoTo FillComboBoxFromMDB_ErrHandler
  
      Set DB = OpenDatabase(sDBName, False, False)
  
      If Not DB Is Nothing Then
          Set DBRecordset = DB.OpenRecordset(sSQL)
          If Not DBRecordset Is Nothing Then
              If DBRecordset.RecordCount &gt; 0 Then
                  Call FillComboBoxFromMDB.AddItem(DBRecordset.Fields(0).Value)
                  ' ^^ This row gives the "Object variable or With block variable not set"
              End If
          Else
              Call WriteLog("Unable to execute " &amp; sSQL)
          End If
          DB.Close
      Else
          Call WriteLog("Unable to open " &amp; sDBName)
      End If
  
      Exit Function
  FillComboBoxFromMDB_ErrHandler:
      Call WriteLog("FillComboBoxFromMDB() error: " &amp; Err.Number &amp; " " &amp; Err.Description)
  End Function
  </code></pre>
  
  <p>I call the function like this.</p>
  
  <pre><code>Private Function Test()
      ' Fill the combobox
      frmMyForm.cmbMyCombo = FillComboBoxFromMDB("Database.mdb", _
                                                 "SELECT MyTable.MyText FROM MyTable")
  End Function
  </code></pre>
  
  <p>So basically I understand that this comes down to instantiation, but I haven't found anything useful about it online. The New keyword doesn't work like it works in VB.Net. How do I instantiate the FillComboBoxFromMDB combobox so that the function will work? Is it even possible?</p>
  
  <p>Thanks in advance!</p>