We're trying to load data from Access Database using VBA to Excel. But our code doesn't work fine.
SQL1 = "SELECT Name " & _
SQL1 = SQL1 & "FROM February" & _
SQL1 = SQL1 & "WHERE Gender = 'F'" & _
SQL1 = SQL1 & "ORDER BY Name"
Set rs1 = db.OpenRecordset(SQL1, dbOpenSnapshot)
If rs1.RecordCount = 0 Then
MsgBox "No data retrieved from database", vbInformation + vbOKOnly, "No Data"
GoTo SubExit
Else
rs1.MoveLast
recCount = rs1.RecordCount
rs1.MoveFirst
End If
xlSheet.Range("B28").CopyFromRecordset rs1
We're getting an error of "Type Mismatched" in the line:
Set rs1 = db.OpenRecordset(SQL1, dbOpenSnapshot)
Can anyone help us and explain us why we're getting that error?