B
ben.manring
I have a form bound to a table, say TableA. From this form, call it
FormA, I lauch another form, call it FormB, which is bound to TableB.
The primary key of TableA is linked to a field of TableB by a
one-to-many relationship with referential integrity enforced. I have
placed a toggle button on FormA that launches FormB. When FormB is
launched from FormA the FormB records are filtered such that only those
records related to the current FormA record are displayed, rather like
the case with a subform.
When I enter new data in FormA, I save it just before FormB is launched
by using the
If Me.Dirty Then Me.Dirty = False
Do.Cmd OpenForm "FormB"
technique, with this code in the Click event of the toggle button that
launches FormB. This works fine as long as FormB is not open already
and I only launch FormB after entering the primary key data into FormA.
The problem is that I like to browse through my data on FormA using the
record navigation buttons while FormB is open. As I do so, the data
displayed on FormB changes according to the filter, and everything
works splendidly. But when I decide to add a new record into FormA
while FormB is open, and then I change focus and go to FormB to add a
corresponding record, I get the following error:
"You can't add or change a record because a related record is
required in Table 'TableA'."
I recognize this as being due to the fact that the record just entered
in FormA is not yet saved. I thought I could simply add an
If Me.Dirty Then Me.Dirty = False
line to the LostFocus event of FormA, but this does not do what I
expected. I still get the same error.
I also have to enter the foreign key data manually into FormB under
this condition. Normally this field is filled in for me automatically
using a default value. The default value is
[Forms]![FormA]![SuchAndSuchaTextbox]
So I have two questions:
1) How can I make sure that the FormA record gets saved when I change
the focus to edit FormB? (and will doing so accomplish what I want it
to?)
2) In the special case I've outlined above, how can I make sure the
foreign key field on FormB is updated at the same time I change focus
from FormA to FormB so I don't have to do it manually?
FormA, I lauch another form, call it FormB, which is bound to TableB.
The primary key of TableA is linked to a field of TableB by a
one-to-many relationship with referential integrity enforced. I have
placed a toggle button on FormA that launches FormB. When FormB is
launched from FormA the FormB records are filtered such that only those
records related to the current FormA record are displayed, rather like
the case with a subform.
When I enter new data in FormA, I save it just before FormB is launched
by using the
If Me.Dirty Then Me.Dirty = False
Do.Cmd OpenForm "FormB"
technique, with this code in the Click event of the toggle button that
launches FormB. This works fine as long as FormB is not open already
and I only launch FormB after entering the primary key data into FormA.
The problem is that I like to browse through my data on FormA using the
record navigation buttons while FormB is open. As I do so, the data
displayed on FormB changes according to the filter, and everything
works splendidly. But when I decide to add a new record into FormA
while FormB is open, and then I change focus and go to FormB to add a
corresponding record, I get the following error:
"You can't add or change a record because a related record is
required in Table 'TableA'."
I recognize this as being due to the fact that the record just entered
in FormA is not yet saved. I thought I could simply add an
If Me.Dirty Then Me.Dirty = False
line to the LostFocus event of FormA, but this does not do what I
expected. I still get the same error.
I also have to enter the foreign key data manually into FormB under
this condition. Normally this field is filled in for me automatically
using a default value. The default value is
[Forms]![FormA]![SuchAndSuchaTextbox]
So I have two questions:
1) How can I make sure that the FormA record gets saved when I change
the focus to edit FormB? (and will doing so accomplish what I want it
to?)
2) In the special case I've outlined above, how can I make sure the
foreign key field on FormB is updated at the same time I change focus
from FormA to FormB so I don't have to do it manually?