Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use object in main Function within a sub function

Status
Not open for further replies.

Bullsandbears123

Technical User
Feb 12, 2003
291
US
I have an object that I define and set in the main function. Then I try to reference the object within a sub function and it acts like I never defined the object. Is there a way to do this?

example

Function mymain(abc as string)

Dim objDatabase As Object
Dim objContact As Object
Set objDatabase = CreateObject("ACTOLE.DATABASE")
objDatabase.Open dbName
Set objContact = objDatabase.CONTACT

objDatabase.Open "dbName"

mysub(abc)

objDatabase.close

set objdatabase= nothing
set objcontact=nothing


end function


function mysub(myvar as string)

objContact.lookup myvariable
'some other stuff
end function
 
Place
Dim objDatabase As Object
Dim objContact As Object

at the top of the code module, not inside the function.
 
Good idea.
Thanks, I solved the problem using Byref. Less memory needed.

I used byref to point to the object

function mysub(byref objcontact as object, myvar as string)

objContact.lookup myvariable
'some other stuff
end function

It works great!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top