VBA Code Help IN CMD.Parameter

lokeshsu

Board Regular
Joined
Mar 11, 2010
Messages
178
Hi all,

I need some help in the below code. i have saved the sql query in access and trying to execute the sql by passing parameters from excel. below is the code which i have coded in vba and i have also added the sql query. i am getting a error like no records found when trying to run the query.

VBA CODE
Code:
    cmd.ActiveConnection = con
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "Passed SLa Query"
    cmd.Parameters.Append cmd.CreateParameter("Process", adVarChar, adParamInput, 6, mProcess)
    cmd.Parameters.Append cmd.CreateParameter("Open", adDate, adParamInput, 10, opn)
    cmd.Parameters.Append cmd.CreateParameter("close", adDBTimeStamp, adParamInput, 20, clos)
    cmd.Parameters.Append cmd.CreateParameter("Prior", adVarChar, adParamInput, 10, Range("A" & a).Value)
     Set rs = cmd.Execute


Do Until rs.EOF Or rs.BOF
    If rs!Expr2 = 0 Then
    passed = passed + 1
    Else
    End If
rs.MoveNext
Loop

The open & closed date is in the format mm/dd/yy hh:mm:ss

SQL QUERY
Code:
SELECT DISTINCT [Union Query].SRNo_Out, Min(Inbound.ActivityCreatedDate) AS MinOfActivityCreatedDate1, Min(Outbound.ActivityCreatedDate) AS MinOfActivityCreatedDate, DateDiff("d",[MinOfActivityCreatedDate1],[MinOfActivityCreatedDate])-(DateDiff("ww",[MinOfActivityCreatedDate1],[MinOfActivityCreatedDate],1)+DateDiff("ww",[MinOfActivityCreatedDate1],[MinOfActivityCreatedDate],7)) AS Expr2
FROM ([Union Query] INNER JOIN Inbound ON [Union Query].SRNo_Out = Inbound.SRNo_In) INNER JOIN Outbound ON [Union Query].SRNo_Out = Outbound.SRNo_Out
WHERE ((([Union Query].Segment)=[process]) AND ((Inbound.OpenedDate) Between [OPen] And [Close]) AND ((Outbound.OpenedDate) Between [OPen] And [Close]) AND (([Union Query].Priority)=[priorit]))
GROUP BY [Union Query].SRNo_Out, DateDiff("d",[MinOfActivityCreatedDate1],[MinOfActivityCreatedDate])-(DateDiff("ww",[MinOfActivityCreatedDate1],[MinOfActivityCreatedDate],1)+DateDiff("ww",[MinOfActivityCreatedDate1],[MinOfActivityCreatedDate],7));
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top