How should macro call VBA function and test the return value? (1 Viewer)

path479

Registered User.
Local time
Tomorrow, 08:59
Joined
Jan 4, 2016
Messages
22
I have a button with embedded marco (using macro builder). The macro carries out a series of actions/command. One of actions is to call a vba function.

The intention is for this vba function to return a value back to the macro which will then carry a series of action based on the returned value.

However I have problem in achieving this. I have tried a number of ways but with no success. Below is one way I tried.

In the macro:

RunCode myFunction(myInt)
If myInt = 1 Then
RunMenuCommand .....
Else if myInt = 2 Then
RunMenuCommand .....
Else
RunMenuCommand....
End If


In the VBA function:

Public Function myFunction(myInt As Integer) As Integer

myFunction = .....

End Function


I know what I am asking is probably a simple question but as I am new the access I am still trying to learn the basic.

Any help and advice will be greatly appreciated. Thank you!
 
Last edited:

Ranman256

Well-known member
Local time
Today, 18:59
Joined
Apr 9, 2015
Messages
4,337
Returning Val's in macros is kinda a pain.
You must build IF blocks, where everything in the block has an ellipsis in the box.
Look this up on how to do it.
 

path479

Registered User.
Local time
Tomorrow, 08:59
Joined
Jan 4, 2016
Messages
22
Returning Val's in macros is kinda a pain.
You must build IF blocks, where everything in the block has an ellipsis in the box.
Look this up on how to do it.

Hi Ranman256.

Thank you for responding. Seems like you were going to include some links or codes that might have been left out. Would you be able to provide those information please? Thank you.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:59
Joined
May 7, 2009
Messages
19,230
first is you create local variable in your macro (SetLocalVar). use your function to return the value. test the result with IF [yourLocalVarName] = ....
 

path479

Registered User.
Local time
Tomorrow, 08:59
Joined
Jan 4, 2016
Messages
22
Thank you arnelgp. Got it working! Thank you again
 

Users who are viewing this thread

Top Bottom