Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / SQL Server / ADP / June 2007

Tip: Looking for answers? Try searching our database.

Passing an adodb.command (which calls a stored procedure)to a func

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RJ - 29 Jun 2007 03:38 GMT
Dim CMD As ADODB.Command
   
Set CMD = Build_SP_Command("spfm_User_SalesLeadSearch_Dynamic")
Execute_SQL_GetRows_Command (CMD)
Set CMD = Nothing

Public Function Execute_SQL_GetRows_Command(CMD As ADODB.Command)
.....
End Function

When the above code executes it blows immediately on the
Execute_SQL_GetRows_Command giving a type mismatch error using the
adodb.command as a passed parameter.  I know that the Set CMD = ...  is
functioning properly; I use it throughout the project without any problem. I
tried throwing a ByRef/Byval at the function but that didn't help.  I have
several functions that return an adodb.command from a function , however this
is the first time I am trying to pass an ADODB.Command to a function.  

Any ideas on the correct syntax for passing an ADODB.Command to a
sub/function?

Thanks for your help!
Sylvain Lafontaine - 29 Jun 2007 04:27 GMT
How is the code inside Build_SP_Command()?  How is the command object and
any eventual parameters created inside this function?

Did you try with another command object created explicitely before the call
to Execute_SQL_GetRows_Command?

If CMD As ADODB.Command doesn't work, try to Dim it as an object.

Signature

Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)

> Dim CMD As ADODB.Command
>
[quoted text clipped - 20 lines]
>
> Thanks for your help!
RJ - 29 Jun 2007 14:02 GMT
This is becoming a head scratacher!   I tried your good suggestion about
passing it as an object however that didn't work either.

If I change the scope of the CMD variable and NOT pass it to the routine
(just use the CMD variable direct) it works just fine!  For this app its okay
to change the scope but there has to be a way to pass an adodb.command to a
function!

> How is the code inside Build_SP_Command()?  How is the command object and
> any eventual parameters created inside this function?
[quoted text clipped - 28 lines]
> >
> > Thanks for your help!
Robert Morley - 29 Jun 2007 15:37 GMT
Unless you're doing this in VB.NET (which is hard to say for sure from your
example), try removing the parentheses from CMD in your function call:

   Execute_SQL_GetRows_Command CMD

Rob

> Dim CMD As ADODB.Command
>
[quoted text clipped - 20 lines]
>
> Thanks for your help!
RJ - 29 Jun 2007 16:48 GMT
We have a winner!  That worked and yes I am working on an ADP.

Thank you for your response

> Unless you're doing this in VB.NET (which is hard to say for sure from your
> example), try removing the parentheses from CMD in your function call:
[quoted text clipped - 27 lines]
> >
> > Thanks for your help!
Robert Morley - 29 Jun 2007 17:55 GMT
Happy to be of service. :)  IIRC, adding parentheses around an object type
will try to pass the default property instead of the object itself.  That's
why you were getting an error message.

Rob

> We have a winner!  That worked and yes I am working on an ADP.
>
[quoted text clipped - 35 lines]
>> >
>> > Thanks for your help!
RJ - 29 Jun 2007 18:26 GMT
Thanks Robert for the clarification.  I truly do appreciate it.

> Happy to be of service. :)  IIRC, adding parentheses around an object type
> will try to pass the default property instead of the object itself.  That's
[quoted text clipped - 41 lines]
> >> >
> >> > Thanks for your help!
Douglas J. Steele - 29 Jun 2007 20:30 GMT
I believe it passes "by value", as opposed to the default "by reference".

You could also use

Call Execute_SQL_GetRows_Command(CMD)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Happy to be of service. :)  IIRC, adding parentheses around an object type
> will try to pass the default property instead of the object itself.
[quoted text clipped - 42 lines]
>>> >
>>> > Thanks for your help!
Robert Morley - 29 Jun 2007 21:02 GMT
Ah, yes, you're right...that's what I was trying to think of earlier.  Am I
right in thinking that when it tries to pass the object By Value, though,
that the "value" of the object will be its default property?  Or am I just
confused on this one?

Rob

>I believe it passes "by value", as opposed to the default "by reference".
>
[quoted text clipped - 48 lines]
>>>> >
>>>> > Thanks for your help!
Douglas J. Steele - 29 Jun 2007 21:50 GMT
To be honest, I'm not sure what passing an object "by value" results in
(other than not what you want!)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Ah, yes, you're right...that's what I was trying to think of earlier.  Am
> I right in thinking that when it tries to pass the object By Value,
[quoted text clipped - 56 lines]
>>>>> >
>>>>> > Thanks for your help!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.