PDA

View Full Version : Solved: Code to bring up a sub form



Aussiebear
04-19-2006, 02:08 AM
I am looking for some help in bringing up a subform when a certain value is entered, IN the example you are roughly working out a bank statment when up comes the infamous Bank Charges. As soon as the value in Bank Charges is greater than zero, a sub form opens to allow you to explain the bank charges bit in greater detail

Main form: Deposits $1200
Withdrawals $360
Bank Charges $50

Subform: Bank Charges;
Greedy Fee $15
Profiteering $20
Rip-off $15

OBP
04-19-2006, 03:35 AM
In the "After Update" event procedure of the field that want to use to trigger the Subform appearing put in

If me![Field Name] > 0 then me![subform name]. visible = True

Where [field name] is your fields name and subform is your subfrom's name.
Don't forget to put

me![subform name]. visible = False

in the Main forms "On Current" event procedure to make the form disappear when you move to the next record.

Aussiebear
04-19-2006, 07:17 AM
Thanks OBP.

Aussiebear
04-19-2006, 12:14 PM
In the "After Update" event procedure of the field that want to use to trigger the Subform appearing put in

If me![Field Name] > 0 then me![subform name]. visible = True

Where [field name] is your fields name and subform is your subfrom's name.
Don't forget to put

me![subform name]. visible = False

in the Main forms "On Current" event procedure to make the form disappear when you move to the next record.

Can I take it that a slight variation of this "code" could be used if you had a normal field data entry of say $10 but only needed the subform to explain a variation by using " If me![Field Name] <> $10 then me![Subform Name].Visible = True" ?

OBP
04-20-2006, 02:31 AM
Yes you can use = (equal to) <> (not equal to) > (greater than) < (less than) and
and you can also use any of the above using the "and" and "or" operators for more than one decision
like this
If me![Field Name] > $10 and me![Field Name] < $100 then me![Subform Name].Visible = True"

will work for any values between 10 and 100



where [full field name] is the

Aussiebear
04-20-2006, 04:40 AM
In the "After Update" event procedure of the field that want to use to trigger the Subform appearing put in

If me![Field Name] > 0 then me![subform name]. visible = True

Where [field name] is your fields name and subform is your subfrom's name.
Don't forget to put

me![subform name]. visible = False

in the Main forms "On Current" event procedure to make the form disappear when you move to the next record.

After entering the above, I received a message which said that it could not find the macro me![FieldName] > 0 then me![subform name].visible = True because I did not save the Macro to main macro group. What does this mean?

I thought I was saving an event procedure both in the After Update and On Current events

OBP
04-20-2006, 05:37 AM
Hi, can you post the zipped database as an attachment so we can have a look.

This code in the "On Current" event procedure of the main form works for me.

Private Sub Form_Current()
If Me![Table2]![table1 id] <> Me![ID] Then
Me![Table2].Visible = False
Else
Me![Table2].Visible = True
End If
and this works in the Fields "After Update" event procedure

If Me![data 1] = "b" Then Me![Table2].Visible = True

Aussiebear
04-20-2006, 05:43 AM
If I could sanitise the database I would....

Aussiebear
04-21-2006, 03:09 AM
This code in the "On Current" event procedure of the main form works for me.

Private Sub Form_Current()
If Me![Table2]![table1 id] <> Me![ID] Then
Me![Table2].Visible = False
Else
Me![Table2].Visible = True
End If
and this works in the Fields "After Update" event procedure

If Me![data 1] = "b" Then Me![Table2].Visible = True

LOL. This late bit wasn't there last night when I last looked. Still better late than never. Thank you.

OBP
04-21-2006, 03:12 AM
Aussie, have a look at the attached database that the code came from.

Aussiebear
04-21-2006, 03:20 AM
Thank you OBP. I'm off to grab a beer then I'll have a quick look