Reusable code forms help for a newbie please!

M

MattieG

Hi
Im hoping someone can give me some guidance on this problem i want to
try and solve.

I basically have bout 6 or 10 forms with a lot of common form
validation for the combo boxes
dates/text boxes etc not to be null etc.

This code for the validation is the same on every form and i was
looking to put it in to a common module
to help with amintainability etc.

The problem i am having is that all the validation is something like

If Me.PaymentID Is Null Then.... prompt user to complete details etc.

If I put this code into a common module the Me. doesnt seem to work.
Do I need to use
Screen.ActiveForm in the common module or do I need to pass in the
form as a variable?

I hope that makes sense but any help would be appreciated.

Mattie
 
W

Wolfgang Kais

Hello Mattie.

MattieG said:
Hi
Im hoping someone can give me some guidance on this problem i want to
try and solve.

I basically have bout 6 or 10 forms with a lot of common form
validation for the combo boxes dates/text boxes etc not to be
null etc.

This code for the validation is the same on every form and i was
looking to put it in to a common module to help with amintainability
etc.

The problem i am having is that all the validation is something like

If Me.PaymentID Is Null Then.... prompt user to complete details etc.

If I put this code into a common module the Me. doesnt seem to work.
Do I need to use Screen.ActiveForm in the common module or do I need
to pass in the form as a variable?

I hope that makes sense but any help would be appreciated.

I think that using Screen.ActiveForm is not the best way to accomplish
you task, because it will not work with subforms and what if the user
is ast enough to change the active form? I suggest to either pass a
reference to the form to your validation procedure, for example:

Private Form_BeforeUpdate(Cancel As Integer)
GlobalValidation Me
End Sub

An alternative is using the CodeContextObject in the global module to
reference the object (form or report) that as called the code.
 
M

MattieG

Thanks wolfgang.

I will try and figure out how to do that, im sure it wont be too
dificult.

Thanks for pointing me in the right direction.

Mattie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top