Best solution for this Parent-Child scenario in Forms?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

MS Access 2K, Windows XP
====================
Hi,

I have separate forms to enter data for the following entities: Meeting,
Agenda and Decisions.
Relationship
------------
[Meeting] (1) ----> (many) [Agenda] and
[Agenda] (1) ----> (many) [Decisions].

MeetingID (PK in tblMeeting) is a FK in tblAgenda.
AgendaID (PK in tblAgenda) is a FK in tblDecision (which has DecisionID as
PK).

I have one form to enter Meeting information (frmMeeting), and a button on
that form opens frmAgenda to enter new Agenda items for that meeting. I'm
passing the MeetingID in the OpenArgs to frmAgenda.

Right now, the user has to close frmAgenda and click on the button on
frmMeeting to add the next new Agenda item. I'd like to add a button on
frmAgenda to add a new Agenda item, thus minimizing the steps for this action.

I'd like to get some feedback if this solution is error-free. It SEEMS to be
working fine, both with the button and the Record Navigation button for the
new record on frmAgenda.

This code is in OnCurrent event of frmAgenda
===================================================
If Me.NewRecord Then
If CurrentProject.AllForms("frmMeeting").IsLoaded Then
Me.MeetingID = [Forms]![frmMeeting]![MeetingID]
End If
End If
===================================================

The form frmMeeting remains open while frmAgenda is open.

Q1. Am I approaching this the right way, and am I missing anything?
Q2. Do I still need to pass MeetingID in OpenArgs to frmAgenda if this code
is correct?

Thanks for your response.

-Amit
 
I think you code is fine. But, since you are asking for some tips...here is
few:

This code is in OnCurrent event of frmAgenda
===================================================
If Me.NewRecord Then
If CurrentProject.AllForms("frmMeeting").IsLoaded Then
Me.MeetingID = [Forms]![frmMeeting]![MeetingID]
End If
End If

I would use the on-insert event. There is no need to fire, and urn this code
all the time just becuase a user moves to another record. If you use the
on-insert event, it will only every fire ONCE when you actually enter some
data into the record. And, if the user opens the record....changes their
mind, and closes the record, then NO blank data is going to be written, or
created. So, the above code could be moved to the on-insert event, and you
only need one line of code since it only executes once when the record is
being inserted.:

Me.MeetingID = [Forms]![frmMeeting]![MeetingID]
Q2. Do I still need to pass MeetingID in OpenArgs to frmAgenda if this
code
is correct?

No, you do not. However, in many cases that frmAganda might be needed to be
used in "several" places in the application. And, this would mean that
frmMeeting might not be opened. This does not seem to be your case..but are
looking for some suggesting as to when, or why using openarges would be an
advantage. If you used openargs, then several different forms in your
application could call frmAganend and simply pass the meedtingID, and thus
no requirement for frmAgend to be opened. It seems in your case that
frmAgenda will "always" be opened from frmMeeting, and thus you don't need
to use openargs. And, you should likely make frmAgenda a model form (this
will force the user to close that form to return back to frmMeeting). If you
don't make it model, then a user might open frmAgdneaq, and then close form
frmMeeting..and your code will fail.

You should also likely force a disk write in the frmMetting code/button that
launches frmAgenda.
 
Hi Albert,

Thanks for your thoughtful response.

Albert D. Kallal said:
I think you code is fine. But, since you are asking for some tips...here is
few:

This code is in OnCurrent event of frmAgenda
===================================================
If Me.NewRecord Then
If CurrentProject.AllForms("frmMeeting").IsLoaded Then
Me.MeetingID = [Forms]![frmMeeting]![MeetingID]
End If
End If

I would use the on-insert event. There is no need to fire, and urn this code
all the time just becuase a user moves to another record. If you use the
on-insert event, it will only every fire ONCE when you actually enter some
data into the record. And, if the user opens the record....changes their
mind, and closes the record, then NO blank data is going to be written, or
created. So, the above code could be moved to the on-insert event, and you
only need one line of code since it only executes once when the record is
being inserted.:

Me.MeetingID = [Forms]![frmMeeting]![MeetingID]

Did you mean BeforeInsert or the AfterInsert event of the form? I didn't see
any OnInsert event......

No, you do not. However, in many cases that frmAganda might be needed to be
used in "several" places in the application. And, this would mean that
frmMeeting might not be opened. This does not seem to be your case..but are
looking for some suggesting as to when, or why using openarges would be an
advantage. If you used openargs, then several different forms in your
application could call frmAganend and simply pass the meedtingID, and thus
no requirement for frmAgend to be opened. It seems in your case that
frmAgenda will "always" be opened from frmMeeting, and thus you don't need
to use openargs. And, you should likely make frmAgenda a model form (this
will force the user to close that form to return back to frmMeeting). If you
don't make it model, then a user might open frmAgdneaq, and then close form
frmMeeting..and your code will fail.

You should also likely force a disk write in the frmMetting code/button that
launches frmAgenda.

Ah. Good point. Thanks.
{If Me.dirty then me.dirty = false}
should achive this?


-Amit
 
Me.MeetingID = [Forms]![frmMeeting]![MeetingID]

Did you mean BeforeInsert or the AfterInsert event of the form? I didn't
see
any OnInsert event......


My sorry. The event I meant is called "Before Insert"
(In my brain...I think of this event as on-insert...as that is what it
does). Once again, my apologies.
Ah. Good point. Thanks.
{If Me.dirty then me.dirty = false}
should achive this?

Yes...the above is good....
 
Albert D. Kallal said:
Me.MeetingID = [Forms]![frmMeeting]![MeetingID]

Did you mean BeforeInsert or the AfterInsert event of the form? I didn't
see
any OnInsert event......


My sorry. The event I meant is called "Before Insert"
(In my brain...I think of this event as on-insert...as that is what it
does). Once again, my apologies.
Ah. Good point. Thanks.
{If Me.dirty then me.dirty = false}
should achive this?

Yes...the above is good....

Thanks, Albert.

-Amit
 
Back
Top