Access Reuse a Button

If I am using the same button on the main form and linked subforms, all on a tab form, please offer how I can copy and paste the same button, without having to modify the code and give the button a new name on each of the subforms.

thanks.
tahirihAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MNelson831Commented:
Copy the code as a function and then call the function instead of repeating the code in every button.


Private Function DoCoolStuff(intID as integer, stData as string)

<execute code here>

End Function

Private Sub Command1_OnClick()
DoCoolStuff me.MyId, Me.Data
End Sub

Private Sub Command2_OnClick()
DoCoolStuff me.MyId, Me.Data
End Sub

Private Sub Command3_OnClick()
DoCoolStuff me.MyId, Me.Data
End Sub

Private Sub Command4_OnClick()
DoCoolStuff me.MyId, Me.Data
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tahirihAuthor Commented:
Thank you.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
MZ TOOLS:
http://www.mztools.com/v3/download.aspx
  which is free, has a copy controls with code function.  Outside of that, there is nothing in Access/VBA that allows you to copy a button.
JimD.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Unfortunately, when you copy and paste a control with code behind, you lose the code.  So, you will have to get the code separately ...

mx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.