Share via

Using a Recordset as the RowSource for a multi-column List Box

Anonymous
2013-08-19T04:19:43+00:00

I have the following code:

Private Sub Form_Load()

    Dim dbs As DAO.Database

    Dim qdf As DAO.QueryDef

    Dim rst As DAO.Recordset

    Set dbs = CurrentDb

    Set qdf = dbs.QueryDefs("qryGetRelatedSPRFNumbers")

    qdf.Parameters("SPRFNum").Value = strSelectedSPRFNum

    qdf.Parameters("AppName").Value = strSelectedProviderApp

    Set rst = qdf.OpenRecordset(dbOpenSnapshot)

    With Me.RelatedSPRFsListBox

        .RowSource = rst

        .Requery

    End With

End Sub

However, when I attempt to compile the code, I get a "Compile error: Type mismatch" error message, with the .RowSource = rst line highlighted.  Please note that qryGetRelatedSPRFNumbers produces records containing data in two fields, and RelatedSPRFsListBox's ColumnCount property = 2.

Is there a way to modify my code so that I can utilize the recordset as the RowSource for the List Box?  Thanks in advance for any assistance.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2013-08-19T05:33:43+00:00

The RowSource property is a string. It can be set to

  • The name of a table.
  • The name of a query.

- A SQL string corresponding to a Select query.

A recordset is an object, not a string, so you can't set the RowSource property to a recordset.

You could create a string variable strSQL, set it to the SQL of the qryGetRelatedSPRFNumbers query and replace the SPRFNum parameter with strSelectedSPRFNum and the AppName parameter with strSelectedProviderApp. Then set the RowSource of the list box to strSQL.

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2013-08-19T19:44:57+00:00

    Thanks for the confirmation.

    Was this answer helpful?

    0 comments No comments
  2. HansV 462.6K Reputation points
    2013-08-19T15:10:41+00:00

    True, but in most situations that shouldn't be a problem...

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-08-19T11:21:49+00:00

    Thanks for your suggestion.  It sounds like I cannot take advantage of the Jet engine's Rushmore technology since I will be executing the query from within VBA using something like dbs.Execute strSQL.  Do you agree?  Thanks again.

    Was this answer helpful?

    0 comments No comments