referencing form fields in modules

joemeshuggah

Board Regular
Joined
Jul 18, 2008
Messages
161
i am trying to learn vba programming on my own...one of the books i have been reading has a brief section on coupling and cohesion...coupling being too putting too many tasks in one procedure. this is exactly what i have been doing in my first attempts at coding. i have a beforeupdate procedure on a form that has become a confusing mess of checks and balances that interfere with one another.

my thought was to create a module for each procedure, and then just do a series of calls in the beforeupdate of the form to make things easier to sort out and test. the only problem is, i cant seem to get the modules to reference the information on the form (e.g. me.MyField is not recognized). is this possible?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
If creating in a Module that is not behind the form you have to refer to the Form Name as well as the control, the word me wont work in the module, but works behind the form modules.
 
Upvote 0
If ther validation called in the beforeupdate is used be multioepl forms rthen it makes sense to put it in a code module. This allows the code to be easily shared between objects.

If the validation called in the beforeupdate is specific to this form then I would not use a separate code module. I would inset procedures in the form's module. This is also called code behind the form.

FWIW:
Most form validation is very specific to that form and it's objects. To me it do not make sense to place that code in a separate module. Using a separate module adds additional overhead.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top