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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing a form object

Status
Not open for further replies.

spence27

Technical User
Feb 2, 2002
28
GB
i am just wonderibg if you can help a new coder out with the following problem.

I need to create a reference to an existing form from a fuction in a module. i then want to pass this object reference into other functions to do this and that.

e.g.
function makeobj(existingFormName)
//create the reference here (somehow)
call subDoThis(existingFormNameReference)
call subDoThat(existingFormNameReference)
end function //makeobj

sub subDothis(aFormReference, newcaption)
aFormReference.Label1.caption = newcaption
end sub

sub subDoThat(aFormReference, componentname)
aFormReference.componentname.delete
end sub

Please can some one point the way.

Thanks#Spence
 
example:

Public Function ReturnFormName(ByRef ioobjForm As Form) As String
ReturnFormName = ioobjForm.Name
End Function
 
One way to reference an existing form is via the Forms collection. All you need to know is the name of the form (e.g., Form1). Try this:

Function MakeObj(ByVal FormName As String) As Boolean
Dim FormRef As Form1

For Each Form In Forms
If Form.Name = FormName Then
Set FormRef = Form
Exit For
End If
Next

call subDoThis(FormRef)
call subDoThat(FormRef)

Set FormRef = Nothing
MakeObj = True

End Function

This is pretty barebones...you'll probably want to throw in some checks to determine if the function should return True or False, etc.

Hope this helps.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top