How do I call a Private Sub MyCode() from another place ?

  • Thread starter Thread starter Isis
  • Start date Start date
I

Isis

If I have a Sub defined;
Private Sub UID_GotFocus()
Me.CSSales.SetFocus
End Sub

How could I call this Sub from another Sub or from another field event ?

Thanks
 
just add Me.CSSales.SetFocus to the sub (but watch out "where" in the code
you place it as it "may" affect something else you have done

or

click the control on the form and slect build (...) then add
Me.CSSales.SetFocus
 
Hi Wayne, Thanks for the reply, but I think I may have explained myself
badly - I want to have blocks of code (routines) that I can call from
anywhere - so, if I want to do some validation for a field in a form and
it is a long piece of code can I - place it in a;

Private Sub MyCode()
My validation code here !
End Sub

Then call this from the 'Validation Rule' of the control and in addition
call it from other places as well. The code I gave was for illustation
only :-)

I have got a load of code in the Update method that I would like be able
to call from other places as well.


Thanks for the reply.
 
Hi

From access press F1 and search on
"create a module"

You will get a page showing the basics from createing a module to examples
of different codes
 
If you use the keyword Private, the sub or function will only work for that
particular module.

You will have to do one of these two things:

1. change the word to Public

or

2. create a new Public method in that module that calls the private method.

Take care
Rui
 
Back
Top