Passing arguments in module function

aqif

Registered User.
Local time
Today, 21:24
Joined
Jul 9, 2001
Messages
158
Hi :)

I am trying to pass an argument in my module function. Right now I just want help by giving you all a simple problem.

Lets suppose I have two Forms....FormOne and FormTwo...I want to build a function like this

Function GiveMessage(StrFormNumber as Integer)

Dim StrMsg as String

If StrFormNumber=1 Then
StrMsg="Function is Executed in FormOne"

ElseIf StrFormNumber=2 Then
StrMsg="Function is Executed in FormTwo"

End If

End Function

The way I want use my Function is somewhat like that

On Command Button in FormOne I want to write

GiveMessage(1)

and It should give me message that Function is Executed in FormOne. And If I will pass 2 as function argument then it will give the other message. I am not sure that I am making sense or not but hope someone will understand what I am trying to do.

Cheers!
Aqif
 
I see no flaw in your logic. It should work as you describe. You might want to add "As Boolean" at the end, so the function returns a value...
 
A function is generally used to return a value to the calling program. If this is what you want then you can write the following:

Code:
Function GiveMessage()

GiveMessage = "Function is Executed in " & Screen.ActiveForm.Name

End Function

If you want the function to display a Message Box to the user, then the following could be used:

Code:
Function GiveMessage()

MsgBox "Function is Executed in " & Screen.ActiveForm.Name, vbOkOnly + vbInformation

End Function

HTH,

Steve A
(p.s. Sorry about the absence of error handling code)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom