Finding the source name in standard module

johnnixon

Registered User.
Local time
Today, 13:36
Joined
Jul 27, 2006
Messages
17
I am a total beginner at modules, but want to create a standard module which handles enabling and disabling etc of a group of buttons (New, Edit, Delete, Escape, OK), which appear with the same names and functions on a large number of forms in the database (Access 97). To do this, I think the code must include the name of the form from which it was called (e.g. Forms!SourceForm.BtnNew.Enabled=False). Do I declare a global variable and then assign it the form name before calling the standard module? If so, where do I declare it so that it's already dimensioned before it's needed? Presumably I only declare it once, so it can't be in the form module for each of the individual forms. Do I declare it As String or As Form? And how do I use it in the standard module? Do I need to create another variable to place it in the code?
Any help much appreciated, but hopefully in terms I can understand at my level.
Thanks
John
 
Last edited:
No need for a variable. Have your Sub/Function accept it as an argument (string).
 
CodeContextObject

Could you use

CodeContextObject.Name

See example (AC97) attached.. three forms, one common module



HTH Regards
 

Attachments

Thanks very much, gentlemen. pbaldy, your solution sounds simple to do, but I haven't found the trick yet. John471, very good of you to create a mockup dB, which works fine. However, I'm still wrestling with the code to really understand it.
I'm in the debt of both of you
Kind regards
John
 
pbaldy - did as you said - gets the form name to the module just fine (used info in one of your recent postings to do breakpoint & F8). In the module, the form name arrives as: Sub NewBtn(FormName As String) - at this point it has the form name as a string variable - hovering the mouse cursor over it shows: FormName="ManuscriptTitleForm"
My next line: Forms!FormName.BtnNew.Enabled=False sets off looking for a form called FormName. Hovering over it shows nothing.
How should I use the string to point to the form?
As I said, I'm a complete greenhorn at coding.
Cheers
John
 
for use with almost anything where you use an exclimation point (bang).

there are two ways of calling on the specific part of what your doing.

one is an absolute, if you use the exclimation point. for example:
Code:
Forms!FormName.BtnNew.Enabled=False
that is looking for a form named 'FormName'

however if you replace it as follows:
Code:
Forms(FormName).BtnNew.Enabled=False
it is looking for form with the name of what is contained within the varaible FormName (in this case "ManuscriptTitleForm")

this also works for, like i said, almost anything else where you use the bang punctionation (exclimation point), most commonly with recordsets.
 
Thanks Elbweb
That's certainly picking up the string now. Unfortunately now generating another error (Application-defined or object-defined error), but not part of this solution I think. Have no idea how to tackle it, but will blunder through it for a while. Had anyway made an error in trying to disable a control while it had the focus, so have shuffled the code around a bit. Have replaced the new first line: Forms(FormName).BtnOK.Enabled=True
with: Forms!ManuscriptTitleForm.BtnOK.Enabled=True
and it still comes up with this error, so nothing to do with your solution to the previous problem.
Thanks for your help
John
 
Fool that I am, I had absent-mindedly renamed the button - it couldn't be found. Your solution now works a treat, Elbweb.
Cheers
John
 
great to know, hope everything else works as smoothly.
 
great to know, hope everything else works as smoothly.
 
great to know, hope everything else works as smoothly.
 
great to know, hope everything else works as smoothly.
 

Users who are viewing this thread

Back
Top Bottom