I have a form with 6 dropdown fields that feeds into a query. I want the query to be exported to Excel if the user selects that option via a command button. I am however getting the error:
Run-time error '3061':
Too few parameters. Expected 6.
I'm assuming this is because the form itself has 6 fields and I only tested a value in 1. However I want the user to be able to select as many or as little fields as desired and I have the query written to return everything for the fields that are Null via criteria in each of those fields as:
IIf([Forms]![frmBuildCustomReport]![cboContractor] Is Null,"*",[Forms]![frmBuildCustomReport]![cboContractor])
etc. So I'm not sure why the error is occurring. Do I also need something in the VBA like For Each Parameter If IsNull prm.Value Then "*"...?
Here is my code:
Thank you SO much for any help!!
Run-time error '3061':
Too few parameters. Expected 6.
I'm assuming this is because the form itself has 6 fields and I only tested a value in 1. However I want the user to be able to select as many or as little fields as desired and I have the query written to return everything for the fields that are Null via criteria in each of those fields as:
IIf([Forms]![frmBuildCustomReport]![cboContractor] Is Null,"*",[Forms]![frmBuildCustomReport]![cboContractor])
etc. So I'm not sure why the error is occurring. Do I also need something in the VBA like For Each Parameter If IsNull prm.Value Then "*"...?
Here is my code:
Code:
Dim dbs As DAO.Database
Dim rstGetRecordSet As Recordset
Dim objXL As Object
Dim objCreateWkb As Object
Dim objActiveWkb As Object
Set dbs = CurrentDb
Set objXL = CreateObject("Excel.Application")
Set objCreateWkb = objXL.Workbooks.Add
Set objActiveWkb = objXL.Application.ActiveWorkBook
objXL.Visible = True
objActiveWkb.Sheets.Add
objActiveWkb.Worksheets(1).Name = "Penetrations"
Set rstGetRecordSet = dbs.OpenRecordset("qryBuildCustomReport")
objActiveWkb.Worksheets("Penetrations").Cells(1, 1).Value = "Test"
objActiveWkb.Worksheets("Penetrations").Cells(2, 1).CopyFromRecordset rstGetRecordSet
Set objActiveWkb = Nothing
Set objCreateWkb = Nothing
Set objXL = Nothing
rstGetRecordSet.Close
dbs.Close
Set rstGetRecordSet = Nothing
Set dbs = Nothing
DoCmd.Close acForm, "frmBuildCustomReport"
Thank you SO much for any help!!