Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Returning an Object variable from a VB Function

hitesh_kapadiahitesh_kapadia Member Posts: 6
Hello,

I am creating one VB DLL project in which I am writing the functions. I am writing one function in which I am creating the database connection & storing it an object. I want to return this connection object to my calling function. The function is defined as

Public Function openConn() as Object
Dim ConnObj as New ADODB.Connection

ConnObj.Open "trial","sa",""
openConn = ConnObj

End Function

The above function is written in .BAS file

I am calling the above function by statement

Conn = openConn()

which is called from the .CLS file. It gives an error
'Object Variable or With block variable not set'

I am creating the Connection Object in the .BAS file because the same Connection Object will be used by number of .CLS files.

Can anybody help me?

Thanks in advance
Hitesh

Comments

  • HaroldDavisHaroldDavis Member Posts: 7
    : Hello,
    :
    : I am creating one VB DLL project in which I am writing the functions. I am writing one function in which I am creating the database connection & storing it an object. I want to return this connection object to my calling function. The function is defined as
    :
    : Public Function openConn() as Object
    : Dim ConnObj as New ADODB.Connection
    :
    : ConnObj.Open "trial","sa",""
    : openConn = ConnObj
    :
    : End Function
    :
    : The above function is written in .BAS file
    :
    : I am calling the above function by statement
    :
    : Conn = openConn()
    :
    : which is called from the .CLS file. It gives an error
    : 'Object Variable or With block variable not set'
    :
    : I am creating the Connection Object in the .BAS file because the same Connection Object will be used by number of .CLS files.
    :
    : Can anybody help me?
    :
    : Thanks in advance
    : Hitesh
    :
    Your real close try this.

    Set conn = openconn

    Hope this helps.
    Harold L. Davis



  • hitesh_kapadiahitesh_kapadia Member Posts: 6
    Hello,

    Thanks very much Harold. I got it.

    Thanks again.
    Hitesh

    : : Hello,
    : :
    : : I am creating one VB DLL project in which I am writing the functions. I am writing one function in which I am creating the database connection & storing it an object. I want to return this connection object to my calling function. The function is defined as
    : :
    : : Public Function openConn() as Object
    : : Dim ConnObj as New ADODB.Connection
    : :
    : : ConnObj.Open "trial","sa",""
    : : openConn = ConnObj
    : :
    : : End Function
    : :
    : : The above function is written in .BAS file
    : :
    : : I am calling the above function by statement
    : :
    : : Conn = openConn()
    : :
    : : which is called from the .CLS file. It gives an error
    : : 'Object Variable or With block variable not set'
    : :
    : : I am creating the Connection Object in the .BAS file because the same Connection Object will be used by number of .CLS files.
    : :
    : : Can anybody help me?
    : :
    : : Thanks in advance
    : : Hitesh
    : :
    : Your real close try this.
    :
    : Set conn = openconn
    :
    : Hope this helps.
    : Harold L. Davis
    :
    :
    :


Sign In or Register to comment.