Solved

Error passing Arrays to Function

Posted on 2014-11-26
8
179 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

829 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