Passing Parameter Arguments to a Query (1 Viewer)

hascons

Registered User.
Local time
Yesterday, 20:50
Joined
Apr 20, 2009
Messages
58
Hello,

I have a project in which I need to populate an already designed Excel form. I use an access database to store the data. I have created a query that assembles the needed data. I filter this data down by using a (StartDate,EndDate, and Project ID) Parameter. To make this easier to filter I have created a form that has (2 TextBoxes, 1 ComboBox, 1 CommandButton).

I have a macro that gets the recordset and copies the data to the proper Excel worksheet. This works when I supply the criteria directly in the query; However when I try to set the criteria to the form controls I get an error message (Too Few Parameters).

I'm not sure how to supply the Parameter arguments to the query ( These should be based on the Form Controls) when I try to open the recordset in VBA.

I've attached a Shortened portion of the code here. If I can get the recordset to open properly the rest of the macro Works. I'm using the Debug.Print rs.RecordCount to determine if any records were returned.

Does any one know why I'm getting the (Too Few Parameters) Error.

Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim xlapp As Excel.Application
Dim xlwk As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim xlformsheet As Excel.Worksheet
Dim StrFile As String

' Check That All Boxes Are Filled In
If IsNull(Me.Enddate) Then
MsgBox "You Must Enter An End Date"
Me.Enddate.SetFocus
Exit Sub
ElseIf IsNull(Me.cmbProject) Then
MsgBox "You Must Select A Project"
Me.cmbProject.SetFocus
Exit Sub
End If

' Open Certified Payroll export Query
Set Db = CurrentDb
Set rs = Db.OpenRecordset("certified payroll export", dbOpenSnapshot)

Debug.Print rs.RecordCount

' Close everything and set object variables to nothing
rs.Close
Db.Close

Set Db = Nothing
Set rs = Nothing
Set qdf = Nothing
Set xlapp = Nothing
Set xlwk = Nothing
Set xlsheet = Nothing
Set xlformsheet = Nothing
 

Users who are viewing this thread

Top Bottom