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
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

Signature
Good Luck
BS"D
> 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.
[quoted text clipped - 10 lines]
> “AfterUpdate” event but nothing happens when I enter the acct #. I would
> appreciate your help. Thanks
Don S. - 17 Jul 2007 13:36 GMT
Thanks. This helped. If I want to make this OR "396" do I just add similar
code to what you gave me?
> Use code instead of Macro
>
[quoted text clipped - 21 lines]
> > “AfterUpdate” event but nothing happens when I enter the acct #. I would
> > appreciate your help. Thanks
Douglas J. Steele - 17 Jul 2007 13:50 GMT
Me.[Vehiclessbf].Visible =((Me.[Account#]="392") Or (Me.[Account#]="396"))

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> Thanks. This helped. If I want to make this OR "396" do I just add
> similar
[quoted text clipped - 29 lines]
>> > would
>> > appreciate your help. Thanks
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
> 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:
[quoted text clipped - 8 lines]
> "AfterUpdate" event but nothing happens when I enter the acct #. I would
> appreciate your help. Thanks