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

Is it Possible to Define a Funciton from Event Procedure 2

Status
Not open for further replies.

dmon000

Technical User
Sep 9, 2003
79
US
Is it possible to define a function as the result of an event procedure of a command button or form?

My problem: I have 18 different command buttons which I would like to define the following function:

Function ReturnWard()
Dim MyVar As String
MyVar = "11"
ReturnWard = MyVar
End Function

For each different button, I need the function to have a different value in the "MyVar" line. These different values will be called in a query criterion box which calls the "ReturnWard() function.

I want to use one query to get 18 different record sets into a form based on the cmd button clicked. So the function value has to change for each of the 18 buttons.

Is this possible?
 
Use a global variable retrieved by your function and set by each event procedure.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or,
depending on what dictates the value of MyVar,
you could use the source as an argument, to your function.

On Click Event of each cmdButton..
If TextBox on current form
"= ReturnWard([txtMyVar])"

If "random value"
"= ReturnWard(6)"
etc...
 
How are ya dmon000 . . .

Agree with [blue]PHV[/blue]. In the [blue]Declaration Section[/blue] of a [blue]module[/blue] in the [blue]modules[/blue] window you would have:
Code:
[blue]Option Compare Database
Option Explicit

[b]Public MyVar[/b][/blue]
In the same module the function would be:
Code:
[blue]   Function ReturnWard()
      ReturnWard = MyVar
   End Function[/blue]
Each command button would have:
Code:
[blue]   MyVar = "[purple][b][i]StringValue[/i][/b][/purple]"[/blue]
[blue]Your Thoughts? . . .[/blue]

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

Be sure to see FAQ219-2884:
 
Thanks for your replies.

I understand the concepts involved. Just can't figure out how to set a global variable in an event procedure and then retrieve it by the function. I have about 20 pounds of books here on VB and I'm not getting the code right.

 
THANKS TO PHV FOR THE GENERAL CONCEPT!!

AND THANKS THANKS THANKS TO ACEMAN FOR THE CODE!!!
IT WORKS.

I was getting close on my own, but it probably would have taken me another 2 days to get right.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top