MSAccess - Access all the controls in a form

  • Thread starter Thread starter coolman
  • Start date Start date
C

coolman

Hello,
Im in the process of coding an MSAccess application which demands
this req.
I have 30 command buttons in a form. Now, I need to find out which of
these 30 command buttons have been clicked. One crude way of doing it
would be to have 30 onclick functions. Are there any workarounds.

can i do some thing like this.

for each control in form
if control type=commandbutton then
msgbox commandbutton.caption
end if
next control

Any help would be greatly appreciated.

Cheers,
Coolman.
 
Hi,


Screen.ActiveControl may help, but it is hard to "debug" since the
immediate debug window switch the "active" status out of the intended
control, when the debugger runs line by line...


Hoping it may help,
Vanderghast, Access MVP
 
Hi coolman,

This may be one idea
(not done this before though).

A toggle button of a "frame" control
looks like a command button.

You can delete the frame's label
and make the frame's border transparent.

If it were named "opt1",
in form load event,

Me!opt1=null

so none are selected.

At end of opt1's On_Click event,
write same stmt.

Just a thought.

Good luck,

Gary Walter
 
Hello,
Im in the process of coding an MSAccess application which demands
this req.
I have 30 command buttons in a form. Now, I need to find out which of
these 30 command buttons have been clicked. One crude way of doing it
would be to have 30 onclick functions. Are there any workarounds.

can i do some thing like this.

for each control in form
if control type=commandbutton then
msgbox commandbutton.caption
end if
next control

Any help would be greatly appreciated.

Cheers,
Coolman.

Hello,
Thanks for posting the replies. But now the question would be,
where would I use the SCREEN.ACTIVECONTROL function. I would need a
"Common" function to in place of all the command button click event
function, inorder that I can use it to capture the click event and
then determine which button has been clicked.

Cheers,
Coolman.
 
Hi,


Exactly that.

Select all the controls, have the property sheet available, and, in front of
the desired event (onClick, I imagine), type

= myFunc( )

Then, in the form, define a FUNCTION of the same name, like:

----------------------------------------
Private Function myFunc( )
MsgBox Screen.ActiveControl.Name
End Function
-----------------------------------------

or do whatever had to be done. Note that ActiveControl return a whole
Control object, not just the value hold in the control.


Hoping itmay help
Vanderghast, Access MVP
 
Back
Top