Hi guys,
Whilst I am still learning about Access and VBA I'm not a total "newbie" and have developed a large application.
I now want to tidy up the code so as I have a lot of code duplicated from form to form. For example, I have a form (called Form1) that has a number of buttons that have "On Click" events that initiate some VBA code such as generate a report etc. I then want to create another form (Form2) that does some other stuff as well as have a button that also runs the same report that was able to be run on Form1.
In order to do this I just copy and past the code from Form1 to Form2 button On Click event...
This all works fine except when I have to change the VBA code I need to change it in 2 places.
I thought that I could create a new module and then create a Function and then call that function but I am getting errors when I compile the VBA code saying "Invalid Use of ME keyword" as I assume due to me creating variables and then setting them to controls on the forms:
Dim mCompanyName As Variant
Dim mReminderCount As Variant
mReminderCount = Me.ReminderCount
mCompanyName = Me.CompanyName
Am I missing something?
Is there a way to tell VBA to automatically "include" a chunk of code?
Thanks for your help
Cheers
Greg
Whilst I am still learning about Access and VBA I'm not a total "newbie" and have developed a large application.
I now want to tidy up the code so as I have a lot of code duplicated from form to form. For example, I have a form (called Form1) that has a number of buttons that have "On Click" events that initiate some VBA code such as generate a report etc. I then want to create another form (Form2) that does some other stuff as well as have a button that also runs the same report that was able to be run on Form1.
In order to do this I just copy and past the code from Form1 to Form2 button On Click event...
This all works fine except when I have to change the VBA code I need to change it in 2 places.
I thought that I could create a new module and then create a Function and then call that function but I am getting errors when I compile the VBA code saying "Invalid Use of ME keyword" as I assume due to me creating variables and then setting them to controls on the forms:
Dim mCompanyName As Variant
Dim mReminderCount As Variant
mReminderCount = Me.ReminderCount
mCompanyName = Me.CompanyName
Am I missing something?
Is there a way to tell VBA to automatically "include" a chunk of code?
Thanks for your help
Cheers
Greg