Shubham
Shubham

Reputation: 979

Access VBA: Setting RecordSource of form as a RecordSet

I have two form. One will display records form a RecordSet that the other form will point to.

    Private Sub Form_Load()

        Dim rs As ADODB.Recordset
        Set rs = CurrentDb.OpenRecordset(Forms("reportSelection").Controls("reportComboBox").value)
        RecordSource = rs

    End Sub

So, when the display form loads, it will grab the value from a combobox populated with recordset names in the other form, and open it as a recordset.

But I'm getting a type mismatch at RecordSource = rs, I dont understand why, how is RecordSource a different type than RecordSet?

Any help is appreciated! Thanks!

Upvotes: 3

Views: 26983

Answers (1)

Jacob
Jacob

Reputation: 43209

You need to supply a SQL query as a String to the RecordSource Property.

Private Sub Form_Load()
    Me.RecourdSource = "SELECT Hello FROM World" 
End Sub

Some docs you might find helpful.

Upvotes: 6

Related Questions