referencing control properties from within control event (1 Viewer)

duug77

New member
Local time
Today, 06:30
Joined
Sep 28, 2011
Messages
5
Is there a key word to reference a control's properties from within a control event, similar to the way that you can reference the form that you're in using the "Me"?

For example if I'm in a sub routine on a form, I can call Me.[ctrl].[property], but I want to do this more generically. I have a series of buttons that all call different forms, but they perform basically the same function. My ideas was that I could put the form name in the button tag and just use the same code for each button

DoCmd.OpenForm [frmCtrlTag]

Does this make sense at all?
 

MarkK

bit cruncher
Local time
Today, 06:30
Joined
Mar 17, 2004
Messages
8,180
Yeah, that makes a ton of sense, but a drawback of using the tag property of the control is that it's sort of invisible. To see the value of that property for a set of controls, for instance, you have no choice but to open a property sheet for each control one at a time.
Consider calling a single generic routine from each of your click handlers like this ...
Code:
private sub cmdMyButton1_Click()
  MyOpenForm "Form1"
end sub

private sub cmdMyButton2_Click()
  MyOpenForm "Form2"
end sub

private sub cmdMyButton3_Click()
  MyOpenForm "Form3"
end sub

private sub MyOpenForm(FormName as string)
  docmd.openform formname
end sub

See what happens there? It has the advantage that all the functionality is visible at a glance. You don't need to open a series of other windows to find out how it works and what the settings are.
Cheers,
 

duug77

New member
Local time
Today, 06:30
Joined
Sep 28, 2011
Messages
5
I get it. Much easier to debug and manage if you don't actually have to check the properties of all the controls on the form. Thanks for the inpu.
 

MarkK

bit cruncher
Local time
Today, 06:30
Joined
Mar 17, 2004
Messages
8,180
Yup, exactly, and you are welcome.
Mark
 

Users who are viewing this thread

Top Bottom