Subform Events Question.. Please Help

  • Thread starter Thread starter HandA
  • Start date Start date
H

HandA

I have a main for and a subform

In the subform I am trying to trap BeforeInsert or whatever so that when I
record is being inserted it will set a certain field to "MAJ"

For some reason it appears that none of the subform's events ever fire.

I looked at Northwind and it has subforms whose events seem to fire even
though the subform is embedded in a main form.

What am I doing wrong?

Thanks
 
The form's BeforeInsert event may not fire if the form is being dirtied
programmatically.

For example, if you have code in its Current event, and the code assigns a
value to a control, the record is already dirty.
 
Thanks Allen,

Well, I am a fairly newbie at Access although very experienced in SQL
Server, VB and MDB files.
Just the forms part of Access that I am unaccustomed to.

Here is what is happening.

I have a recipe form--main form.

On it is a tab control. In each tab control is a subform. Each subform
shows a certain type of ingredient. All of these come from the same table.

Anyhow, the problem is this. The subform shows as a datasheet. One of the
fields is type of ingredient--I base this on which subform they are using.
So if they are using the Major tab it is a "MAJ" ingredient. type of
ingredient is a NOT NULL field and when the person starts adding a new
record I want the subform event to stuff "MAJ" in that field automatically.
The field will be hidden from the user on the form, but I need it as MAJ,MIN
and other types of ingredients are all stored in the same table as
ingredients of the recipe.

But I opened the sub form, and tried trapping many events, by putting MSGBOX
lines in them.
None of them fire.

Thanks,

Shane
 
Here's a code-free solution.

Place a text box on the main form, with these properties:
Name txtMaj
ControlSource ="MAJ"

For the subform that is supposed to show the major ingredient, set these
properties:
LinkMasterFields txtMaj
LinkChildFields IngredientType (or whatever the subform field is
called).

The IngredientType will automatically inherit the matching value from the
text box on the main form. Repeat for your other subforms.

The subform events should still fire (assuming it is bound) so that approach
should have worked also.
 
Yes, Shane.

I agree that the interface you are describing here would not work with a
relational structure. Better to redesign the interface to one that will
work, I suspect.
 
Allen,

I just can't understand why subform events don't fire when the subform is on
a mainform.

I know I have read that it is actually in a subform control that is on the
main form so maybe that prevents the events from firing somehow.

But then there has to be a way to set a field in a subforms new record.....

I sure haven't found it but seems this would be a very common need.

Thanks,

Shane
 
Shane, I don't pretend to understand what you are trying to do, but if you
are under the impression that the events of a form do not fire when the form
is a subform, that impression is erroneous.

There may be specific instances when events to not fire (e.g. if you dirty
the record programmatically, then Form_Dirty or Form_BeforeInsert may not
fire in particular versions of Access), but that has nothing to do with the
form being a subform.
 
Thanks for trying to help me.

I found out that since mgmt made me change things and I had to get rid of a
field.
When I got rid of that field it replaced the subform on the main form
apparently with just a query.

That is why it wasn't working.

I have it working now.

Shane
 
Back
Top