The Linux Page

Strong typing for a Recordset failing

When I looked around for samples on how to query a MS-Access database using an SQL statement, it was telling me to declare a record set variable of type Recordset.

Option Explicit

Sub Function Load(where As String)
	Dim sql As String
	Dim rcd As Recordset

	sql = "SELECT * FROM table WHERE " & where
	Set1 rcd = CurrentDb.OpenRecordset(sql)
End Sub

The OpenRecordset() function, in my MS-Access 2007 installation at least, returns a Recordset2, not a Recordset.Once I changed the declaration of the rcd variable to Variant2 instead of Recordset, it worked.

	Dim rcd ' As Recordset -- no strong type because Recordset2 is expected

Why don't I just use Recordset2 here? Because MS-Access does not know about it.

  • 1. The Set is necessary. I'm not too sure why, but without it you get an error.
  • 2. Variant—This means the rcd variable is not strongly typed anymore.

SMS From Me Logo

SMS From Me

To automatically start one on one conversations with your online leads.