How: macro to close/open forms based on a control's value?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a particular control (check box) where if it is checked, then I need
an additional form to open and then the original form to close (these forms
are from related tables); whereas if it is not checked, I need the form to
close without opening the new form.

I think I can use an If Then statement of some kind- but I am not sure the
best way.

The control that the Open New Form operation/action is dependant on, is
earlier in the tab order, however all controls must have a response so I
would use an On Update property event on the last control in the tab order.
 
you need to use a conditional statement in your macro. try the following,
substituting the correct control and form names, of course:

Condition: <leave blank>
Action: Close
(leave the action arguments blank, to close the active form)

Condition: [MyCheckbox] = True
Action: OpenForm
FormName: MySecondForm
(set the rest of action arguments as needed)

Condition: <leave blank>
Action: StopMacro

so the open form always closes, regardless. if the checkbox control is
checked, then the second form opens.

hth


Julia CHP said:
I have a particular control (check box) where if it is checked, then I need
an additional form to open and then the original form to close (these forms
are from related tables); whereas if it is not checked, I need the form to
close without opening the new form.

I think I can use an If Then statement of some kind- but I am not sure the
best way.

The control that the Open New Form operation/action is dependant on, is
earlier in the tab order, however all controls must have a response so I
would use an On Update property event on the last control in the tab
order.
 
Agree entirely, Tina. Except, just curious, what is the purpose of the
StopMacro action there?
 
you know, it's probably not necessary at all. when i used to write macros by
the ton (back in my pre-VBA days), i had a couple weird experiences early
on, where a macro seemed to "skip" the blank row at the end and move on to
another macro's action, in a multiple-macro sheet. that was back in A95,
which seemed to do all kinds of strange things intermittently - i could
never tell if it was the software glitching, or me! at any rate, i began
explicitly stopping all my macros, as the last action. old habits die hard,
i guess. <g>


Steve Schapel said:
Agree entirely, Tina. Except, just curious, what is the purpose of the
StopMacro action there?

--
Steve Schapel, Microsoft Access MVP

you need to use a conditional statement in your macro. try the following,
substituting the correct control and form names, of course:

Condition: <leave blank>
Action: Close
(leave the action arguments blank, to close the active form)

Condition: [MyCheckbox] = True
Action: OpenForm
FormName: MySecondForm
(set the rest of action arguments as needed)

Condition: <leave blank>
Action: StopMacro

so the open form always closes, regardless. if the checkbox control is
checked, then the second form opens.
 
Ah, ok. Whereas I, who also have a macros-by-the-ton pre-VBA
background, have probably never ever used a StopMacro action. But
anyway, I'm happy, now that I know I wasn't missing something :-)
 
oh, no worries there, Steve. i seriously doubt that you'd ever hear
something from me that would give you a "lightbulb" moment. <g and bow>
 
Dear Tina,

Like you, I learn new stuff every day. I don't recall whether I have
been lightbulbed by you before, but I am certainly open to the
possibility. In my opinion, your contribution in these forums is worthy.
 
thank you, kind sir! <bows again, blushing>


Steve Schapel said:
Dear Tina,

Like you, I learn new stuff every day. I don't recall whether I have
been lightbulbed by you before, but I am certainly open to the
possibility. In my opinion, your contribution in these forums is worthy.
 
Back
Top