PDA

View Full Version : Passing Date Parameter to an outside Action Query using VBA Access



NyDon
09-03-2015, 03:10 PM
Hello All, new to the site. Hoping to get assistance why the following code returns the error “too few parameters”. My objective is to run an action query in another Access database.

Private Sub Command60_Click()

Dim qDate As Variant
Dim db As DAO.Database
Dim qdf As DAO.QueryDef

qDate = #9/1/2015#
Set db = DBEngine.Workspaces(0).OpenDatabase("C:\Users\Donald LT\Documents\Work Database\DatabaseBackends\dashboard.accdb")
Set qdf = db.QueryDefs("TestActionQueryCode")
qdf.Parameters(0) = qDate
db.Execute "TestActionQueryCode", dbFailOnError '<-- Error is here

Set db = Nothing
Set qdf = Nothing

End Sub

NOTE: Not sure if my qDate is declared correctly but I tried setting qdf.Parameters(0) = #9/1/15# resulting in the same error.