I’m trying to export an Access recordset to an Excel file via a little VBA code. The problem is when the export line is read I get a 2498 error (which says I entered an incorrect data type for one of the arguments). Needless to say, I’m not an expert in VBA coding .
Here’s the code:
———————–
Private Sub B_GENERATE_Click()
Dim rs_excel As Recordset
Dim Query, EXCEL_NAME
Set rs_excel = New ADODB.Recordset
Query = “select FIELD_A, FIELD_B, FIELD_C from TABLE where CONDITION”
rs_excel.Open Query, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
EXCEL_NAME = “C:myfolder” & InputBox(“Input Excel file name” & Chr(13) & “(do not include the .xls extension)”, “Input Name”) & “.xls”
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, rs_excel, EXCEL_NAME
End Sub
———————–
Edited to add: I tried the SQL query in the SQL Query Analyzer and it worked
Do you know what might be going wrong?