DanielLazarov
DanielLazarov

Reputation: 160

Setting the Recordset property of an Access form

Getting Run-time error '438', Object doesn't support this property or method.

Edit: The Full code, the DB_CONNECTION is public and set in a different module and it is working.

Function subFormUpdate()
Dim rs As New ADODB.Recordset


With rs
.ActiveConnection = DB_CONNECTION
.Open "SELECT * FROM napr"
End With

If rs.EOF Then

DB_CONNECTION.Execute "CREATE TABLE napr(" _
                & " num int(2) not null unique, " _
                & "name varchar(255) null );"
End If

With Forms!Main!FormDirections!TableDirSubForm.Form
.Recordset = rs
.Requery
End With

End Function

Getting it on ".Recordset = rs", where 'rs' is an ADODB Recordset.

The form is just a Blank subform. Do I have to do anything else in order to view the recordset on the form?

Upvotes: 0

Views: 1832

Answers (1)

Dick Kusleika
Dick Kusleika

Reputation: 33145

The type of recordset returneds by Form.Recordset depends on what kind of file you're using and you don't have any control over it. If you're using a native Access file, the recordset will be DAO. If you're using ADP, the recordset will be ADO. ADP is deprecated in version 2013, but that's why the help says the Recordset property can be either type.

Your likely problem (once you properly include the Set keyword) is that you're trying to assign an ADODB.Recordset object to a DAO.Recordset2 object. You could use the TypeName function at a breakpoint to confirm it. Change your recordset to DAO and it will work.

Upvotes: 2

Related Questions