I'm trying to call a stored procedure in SQL Server with VBA. The stored proc has three parameters, @CC int, @SDate datetime2, @EDate datetime2. I'm able to get the SQL string correct for the integer but once I try to pass the dates, it throws errors. I'll paste the code below
Code:
Dim db As Database, qd As QueryDef, strSQL As String
Dim ConCompany As Long, SDate As Date, EDate As Date
SDate = InputBox("Start date")
EDate = InputBox("End date")
ConCompany = Forms!MainMenuF!cmbCompany
Set db = CurrentDb
Set qd = db.QueryDefs("spApplicationReportPTQ")
qd.Connect = ConString
qd.SQL = "EXECUTE dbo.spApplicationReport " & ConCompany & ", " & SDate & "," & EDate
DoCmd.OpenQuery ("spApplicationReportPTQ")
qd.Close
db.Close
Set qd = Nothing
Set db = Nothing