Solved

Error passing Arrays to Function

Posted on 2014-11-26
8
173 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
Comment Utility
Try this.
? runsp "ElementInRange",Array("Element","Amount","Material"),Array(18,3,18),Array("Cr",22,"2205")

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
or this

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

Author Comment

by:Kurt Bergman
Comment Utility
Okay... tried that
Now I'm getting 'Argument Not Optional'
0
 

Author Comment

by:Kurt Bergman
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 33

Expert Comment

by:Norie
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility
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 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 total points
Comment Utility
or

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

Author Comment

by:Kurt Bergman
Comment Utility
?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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

762 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

9 Experts available now in Live!

Get 1:1 Help Now