I am trying to copy the data from an access query into excel and am using DAO.Recordset to capture the data but am getting a 3061 error. I am a newbie to recordsets and am unsure waht the problem is. I am calling a fuction called exportdata and the first lines of this are:-
The error says too few parameters expected 1 and points to SET rs line? I am at a complete loss as the strQry is showing as set to qryChoose_Patient and I can open this qry in access to show the records.
Can someone please point out where I am going wrong?
Code:
Private Function ExportData(strQuery As String)
Dim intR As Integer
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset(strQuery, dbOpenDynaset) (THIS Line CAUSES ERROR 3061):mad:
rs.MoveLast 'moves to the last record
rs.MoveFirst 'moves back to the first record
If Not (rs.BOF And rs.EOF) Then
xl.Sheets(Sheet1).Select
Else
'There are no records
MsgBox "There are no records for " & strQuery
The error says too few parameters expected 1 and points to SET rs line? I am at a complete loss as the strQry is showing as set to qryChoose_Patient and I can open this qry in access to show the records.
Can someone please point out where I am going wrong?