Hide/Show Subform

G

Guest

I have a main form “CapitalItems†which has a subform “Vehiclesbfâ€. I want
to show “Vehiclessbf†if the field “Acct#†on the mainform is equal to 392.
For all other values I do not want the subform to show.
I am using a macro:
Macro Name: “Hide/ShowVehiclesFormâ€;
Condition: [Forms]![CapitalItems]![Account#]="392"
Action: “SetPropertyâ€
Control Name: Vehiclessbf
Property: Visible
Value: Yes

I reference the macro name in the “Acct#†field of the main form in the
“AfterUpdate†event but nothing happens when I enter the acct #. I would
appreciate your help. Thanks
 
G

Guest

Use code instead of Macro

Me.[Vehiclessbf].Visible = (Me.[Account#]="392")

When the cursor is loacted in the AfterUpdate event of the Account field,
there is a button with three dots, press it and select code view.
Enter the above line in there

Also, if you are moving between records, add the above line to the MainForm
OnCurrent event
 
T

tina

your macro tells Access when to *show* the subform, but does nothing to tell
Access when to *hide* the subform. try adding a couple additional actions to
your macro, as

First line of macro:
Macro Name: "Hide/ShowVehiclesForm";
Condition: [Forms]![CapitalItems]![Account#]="392"
Action: "SetProperty"
Control Name: Vehiclessbf
Property: Visible
Value: Yes

Second line of macro:
Macro Name: <leave blank>
Condition: ... <add the three dots, which are called an ellipsis>
Action: StopMacro

Third line of macro:
Macro Name: <leave blank>
Condition: <leave blank>
Action: "SetProperty"
Control Name: Vehiclessbf
Property: Visible
Value: No

with the above setup, the macro runs each time the control's AfterUpdate
event fires. when the condition on the first line is met, the subform is
unhidden and the macro stops on the second line. when the condition on the
first line is *not* met, the macro skips to the third line and hides the
subform.

as Ofer's post demonstrates, VBA code can do the same thing with a much
shorter statement. i encourage you to begin learning VBA, which is much more
powerful than macros (i'm guessing that still holds true even in A2007); but
don't feel you're wasting time working with macros. for one thing, they
teach you the importance of thinking through both (or all) "sides" of an
action when you're manipulating objects programmatically.

hth
 
G

Guest

Thanks. This helped. If I want to make this OR "396" do I just add similar
code to what you gave me?

Ofer Cohen said:
Use code instead of Macro

Me.[Vehiclessbf].Visible = (Me.[Account#]="392")

When the cursor is loacted in the AfterUpdate event of the Account field,
there is a button with three dots, press it and select code view.
Enter the above line in there

Also, if you are moving between records, add the above line to the MainForm
OnCurrent event

--
Good Luck
BS"D


Don S. said:
I have a main form “CapitalItems†which has a subform “Vehiclesbfâ€. I want
to show “Vehiclessbf†if the field “Acct#†on the mainform is equal to 392.
For all other values I do not want the subform to show.
I am using a macro:
Macro Name: “Hide/ShowVehiclesFormâ€;
Condition: [Forms]![CapitalItems]![Account#]="392"
Action: “SetPropertyâ€
Control Name: Vehiclessbf
Property: Visible
Value: Yes

I reference the macro name in the “Acct#†field of the main form in the
“AfterUpdate†event but nothing happens when I enter the acct #. I would
appreciate your help. Thanks
 
D

Douglas J. Steele

Me.[Vehiclessbf].Visible =((Me.[Account#]="392") Or (Me.[Account#]="396"))


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Don S. said:
Thanks. This helped. If I want to make this OR "396" do I just add
similar
code to what you gave me?

Ofer Cohen said:
Use code instead of Macro

Me.[Vehiclessbf].Visible = (Me.[Account#]="392")

When the cursor is loacted in the AfterUpdate event of the Account field,
there is a button with three dots, press it and select code view.
Enter the above line in there

Also, if you are moving between records, add the above line to the
MainForm
OnCurrent event

--
Good Luck
BS"D


Don S. said:
I have a main form "CapitalItems" which has a subform "Vehiclesbf". I
want
to show "Vehiclessbf" if the field "Acct#" on the mainform is equal to
392.
For all other values I do not want the subform to show.
I am using a macro:
Macro Name: "Hide/ShowVehiclesForm";
Condition: [Forms]![CapitalItems]![Account#]="392"
Action: "SetProperty"
Control Name: Vehiclessbf
Property: Visible
Value: Yes

I reference the macro name in the "Acct#" field of the main form in the
"AfterUpdate" event but nothing happens when I enter the acct #. I
would
appreciate your help. Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top