Solved

Error passing Arrays to Function

Posted on 2014-11-26
8
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 34

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 34

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

695 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