Solved

Error passing Arrays to Function

Posted on 2014-11-26
8
178 Views
Last Modified: 2014-11-26
I'm trying to write a generic stored procedure in vba and pass in parameters as variables

Code snippet:
Public Function RunSP(StoredProcedureName As String, ParamString() As String, DataType() As DataTypeEnum, ParamValue() As Variant)


In the immediate window I have:
? runsp "ElementInRange",("Element","Amount","Material"),(18,3,18),("Cr",22,"2205")

I put the breakpoint on the Function declaration line

It compiles correctly but when I attempt to run it I get
Compile Error  Expected: )  (closing parenthesis)

no clue as to where the missing parenthesis belongs
0
Comment
Question by:Kurt Bergman
  • 3
  • 3
  • 2
8 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 250 total points
ID: 40467474
Try this.
? runsp "ElementInRange",Array("Element","Amount","Material"),Array(18,3,18),Array("Cr",22,"2205")

Open in new window

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40467484
or this

?runsp("ElementInRange",Array("Element","Amount","Material"),Array(18,3,18),Array("Cr",22,"2205"))
0
 

Author Comment

by:Kurt Bergman
ID: 40467485
Okay... tried that
Now I'm getting 'Argument Not Optional'
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:Kurt Bergman
ID: 40467490
Hy Rey,
?runsp("ElementInRange",Array("Element","Amount","Material"),Array(18,3,18),Array("Cr",22,"2205"))

returns: Type mismatch: array or user-defined type expected
0
 
LVL 33

Expert Comment

by:Norie
ID: 40467512
Try changing the function declaration to this.
Public Function RunSP(StoredProcedureName As String, ParamString As Variant, DataType As Variant, ParamValue As Variant)

Open in new window

Also, to test use a small sub - somethings you can't do in the Immediate Wndow.

Actually just realised that enclosing the arguments in brackets, as suggested by Rey, will work.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40467547
Public Function RunSP(StoredProcedureName As String, ParamString As Variant, DataType As Variant, ParamValue As Variant)


then use

?runsp("ElementInRange",Array("Element","Amount","Material"),Array(18,3,18),Array("Cr,22,2205"))
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 40467549
or

?runsp("ElementInRange",Array("Element","Amount","Material"),Array(18,3,18),Array("Cr",22,"2205"))
0
 

Author Comment

by:Kurt Bergman
ID: 40467590
?runsp("ElementInRange",Array("Element","Amount","Material"),Array(18,3,18),Array("Cr",22,"2205")) 

Open in new window

and
?runsp("ElementInRange",Array("Element","Amount","Material"),Array(18,3,18),Array("Cr,22,2205"))

Open in new window



Both work

It's now hanging up here:
ADOCmd.Parameters(ParamString(0)).Value = ParamValue(0)

Open in new window



Error 3421 (Application uses a value of the wrong type for the current operation.)
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now