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

Global function

Status
Not open for further replies.

peljo

Technical User
Mar 3, 2006
91
BG

In my form i have to declare seceral times the following expression:

Dim OfficeBranch As Control
Set OfficeBranch = Me.Controls("Branch" & (Me.Parent.office - 1))

Can i make the above expression to be valid for all the functions in the form, and thus avoid declaring it in each case?
 
Hello

You would do this in the Modules section of Access:

Create a module titled for instance, GlobalValues
then open the module and place your declarations there.
Regards
Mark
 
A cleaner way would be to pass the control to each function.

Here are two functions that I pass a control to

Code:
Public Function demoPassControl1(theControl As Access.Control) As String
  demoPassControl1 = theControl.ControlType
End Function

Public Function demoPassControl2(theControl As Access.Control) As String
  demoPassControl2 = theControl.Name
End Function

and now I can call the two functions like this

MsgBox demoPassControl1(Me.List6)
MsgBox demoPassControl2(Me.List6)
 
as an aside, using MajP's approach, the entire set of controls (and other properties) cna then be obtained via a reference to the Parent property of the control.




MichaelRed


 
How are ya peljo . . .

Consider it still takes a line of code from [blue]each instance[/blue] to call a common routine. The difference to you is longer execution time versus direct as you have it . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top