Advertisement

04.03.2008 at 08:30AM PDT, ID: 23293135
[x]
Attachment Details

Using Excel VBA to construct a multi parameter query in an Access database

Asked by pfmurray in Access Coding/Macros, Microsoft Excel Spreadsheet Software, VB Script

Tags: MS, Office, Excel, Access 2003

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_Location, Sales_Order_Location.Span_Start_Demarc, Sales_Order_Location.Span_End_Location, Sales_Order_Location.Span_End_Demarc, Sales_Order_Location.Span_Fibre_length, Sales_Order_Location.IP_POP, Sales_Order_Location.Notes
FROM Sales_Order_Location
WHERE (((Sales_Order_Location.Sales_Order_Num)=[SO]) AND ((Sales_Order_Location.Span_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("QueryLongParam", adBigInt, adParamInput, , LocSearch)
  .Parameters.Append .CreateParameter("QueryTextParam", 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
[+][-]04.03.2008 at 12:00PM PDT, ID: 21275775

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Coding/Macros, Microsoft Excel Spreadsheet Software, VB Script
Tags: MS, Office, Excel, Access 2003
Sign Up Now!
Solution Provided By: jpeca
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.03.2008 at 02:03PM PDT, ID: 21276938

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.04.2008 at 12:56AM PDT, ID: 21279669

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 02:16AM PDT, ID: 21279937

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 02:25AM PDT, ID: 21279975

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 02:34AM PDT, ID: 21280012

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 02:34AM PDT, ID: 21280014

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628