How to convert Sub to a Function? (1 Viewer)

jai kushwaha

Registered User.
Local time
Today, 11:45
Joined
Nov 1, 2015
Messages
61
how I can make a macro to open run an event on a form
 

jai kushwaha

Registered User.
Local time
Today, 11:45
Joined
Nov 1, 2015
Messages
61
Re: Macro to open an existing form

how to convert subroutine to function?' I want to make a button on my form and want to add an event on_click. the event I want to add on click of button I made the event code but I dont know that how to convert it in function so that I can run in the macro and add it to button on_click event. so can anyone please tell me how to convert the sub code in function.????
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 07:15
Joined
Jul 9, 2003
Messages
16,280
Replace the word Sub with Function throughout the procedure.
 

Grumm

Registered User.
Local time
Today, 08:15
Joined
Oct 9, 2015
Messages
395
Don't forget that a function should return a value.
I don't see why you can't add the sub to the on_click event but you probably have a good reason for that.
Here you can find some explanation about the difference : http://www.baldyweb.com/SubFunction.htm
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 07:15
Joined
Jul 9, 2003
Messages
16,280
There's something odd about calling functions or subs, sometimes you can't call a sub. (I might have the wrong end of the stick- Need to check when I get home) I'll put a link in when I find it.
 

Grumm

Registered User.
Local time
Today, 08:15
Joined
Oct 9, 2015
Messages
395
I saw he mentioned macro's... I never use macro's behind buttons. I always use "Code Builder" and call my sub or function from there. Never had a problem calling subs that way...
 

jai kushwaha

Registered User.
Local time
Today, 11:45
Joined
Nov 1, 2015
Messages
61
how to make a code behind buttons to do event which is already an event on the form with different procedure.

explanation...
I have a form and on the form I have an event on dblclick. now I want to make a button on the same form to do the same thing on button click. now how I can do it??
 

Minty

AWF VIP
Local time
Today, 07:15
Joined
Jul 26, 2013
Messages
10,371
on your buttons on click event

Call yourButtonsDouble_Click
 

Minty

AWF VIP
Local time
Today, 07:15
Joined
Jul 26, 2013
Messages
10,371
if you click the code builder on the on click property in design view on your form.
 

jai kushwaha

Registered User.
Local time
Today, 11:45
Joined
Nov 1, 2015
Messages
61
can anyone tell me what this code mean is??DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70how I can know the number 8 mean in this code??I want full explanation of this code if anyone knows please tell me.thanks in advance....
 

jai kushwaha

Registered User.
Local time
Today, 11:45
Joined
Nov 1, 2015
Messages
61
thank you sir for your help can you please tell me how I can add a button on my form which will run an existing event on same form??
 

Users who are viewing this thread

Top Bottom