Hi
I need to create an Excel VBA statement to query an Access Stored Procedure. I can get it to work with one parameter but I have a query where I need to pass two parameters. The query code in Access is as follows and it works when run directly on the stored procedure
SELECT Sales_Order_Location.Sales
_Order_Num
, Sales_Order_Location.Span_
Number, Sales_Order_Location.Span_
Start_Loca
tion, Sales_Order_Location.Span_
Start_Dema
rc, Sales_Order_Location.Span_
End_Locati
on, Sales_Order_Location.Span_
End_Demarc
, Sales_Order_Location.Span_
Fibre_leng
th, Sales_Order_Location.IP_PO
P, Sales_Order_Location.Notes
FROM Sales_Order_Location
WHERE (((Sales_Order_Location.Sa
les_Order_
Num)=[SO])
AND ((Sales_Order_Location.Spa
n_Number)=
[S]));
The Excel VBA I'm trying to use is as follows :
LocSearch = Me.txtLocNumber + Me.SpinButton1.Value ' gives a number
LineRef = Me.txtLocNumber ' gives a string
On Error Resume Next
MyRecordset.Close
On Error GoTo 0
Set MyCommand.ActiveConnection
= MyDatabase
MyCommand.CommandText = "Location_Span_Query"
MyCommand.CommandType = adCmdStoredProc
With MyCommand
.Parameters.Refresh
.Parameters.Append .CreateParameter("QueryLon
gParam", adBigInt, adParamInput, , LocSearch)
.Parameters.Append .CreateParameter("QueryTex
tParam", adVarChar, adParamInput, 255, LineRef)
End With
MyRecordset.Open MyCommand, , adOpenDynamic, adLockPessimistic
MsgBox "Records found " & MyRecordset.RecordCount
I'm not sure how to apply the appropriate parameter to the right field (or even if this is possible).
Can anyone assist?
Thanks
Pete
Start Free Trial