A family of Microsoft relational database management systems designed for ease of use.
Dear @Maxine Nietz,
Welcome to Microsoft Q&A Forum!
I reviewed the code you shared, and I wanted to point out the specific mistake in your code so you can correct it easily.
In the Microsoft DAO example you referenced, the variable strSQL is declared as a String, and rsSQL is declared as a DAO.Recordset. The SQL text is stored in the string variable, and only the result of OpenRecordset is assigned to the recordset variable.
In your code, however, you used:
Dim lsql As DAO.Recordset
Set lsql = "SELECT ... FROM ..."
This causes a Type Mismatch because you're assigning a String ("SELECT ... FROM ...") directly to a Recordset object (DAO.Recordset). The SQL belongs in a String variable (like strSQL), and only the returned Recordset should be assigned to a Recordset variable.
You can check this article for more details: Database.OpenRecordset method (DAO)
Reference: Type mismatch (Error 13)
Hope this helps clarify the issue for you. Wish you a good day!
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.