Who's your mom, ChildForm?

G

Guest

I have a control button which opens a form that collects information about
the current parent record. It's a check list and so each check box and memo
field is bound to its own specific control source. The records of the child
form are stored in a table of course. The problem is that the button no
matter which parent record it's called from is opening a brand new record,
and not one specific to it's parent record. The control button has started a
daycare center but didn't take note of what kid belonged to what parent and
new parents keep bringing in children that don't belong to them.

I think my mistake was that I created a new AutoNumber for the child form
with a different name. I should have used the same autonumber field from the
underlying table of the parent form. I couldn't figure out how to do this.

Can someone please help?

Nicole
 
T

tina

forms don't have Autonumbers, tables do. forget the forms for a minute; are
the parent and child *tables* properly related in the Relationships window?
if one parent record may have many related child records, but each child
record is related to only one parent record, then you have a one-to-many
relationship between the two entities (tables). each table needs its' own
primary key; plus, the primary key values of the parent records must be
stored in a *foreign* key field (with matching or compatible data type, the
name of the field doesn't matter) in the child records, so you can relate
each child record to a specific parent record.

have you done the above?

if so, then forms are next. if you have a main form bound to the parent
table, and a subform bound to the child table, then open the main form in
Design view, click on the subform control to select it, and open the
Properties box. the LinkMasterFields property should show the name of the
parent table's primary key field. the LinkChildFields property should show
the name of the child table's *foreign key* field.

if your tables are related properly, and the mainform/subform are linked
properly, as described above, then you'll get an automatic link between
parent and child records without any code.

if you're opening a *separate form* to enter the child records, then by
definition the main form is not a parent form, and the second form is not a
subform or child form - it's merely a separate form. you'll have to use code
to create the link between the record showing in the main form, and the
record(s) you review or enter in the second form. if you need help with
that, post back.

hth
 
G

Guest

Tina,

I am using a separate form. I already have a form that works precisely the
way I want it to. The code for that is...

Private Sub MP200_Click()
On Error GoTo Err_MP200_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MP-200 Status"

stLinkCriteria = "[Report No]=" & Me![Report No]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_MP200_Click:
Exit Sub

Err_MP200_Click:
MsgBox Err.Description
Resume Exit_MP200_Click

End Sub

********
Only thing is that I can't remember/figure out how to include"ReportNo"
auto number which comes from my main form into the table of my new form.
Also (and I know this seems irresponsible), the form for the above code
doesn't even have a table on the BE and I can't even remember how I created
it. I've always been able to back track my steps until now.

I tried to install a separate autonumber for my newest form and ran into the
issue at hand. I know I need to get the main form's autonumber onto the
table of this new form. Any suggestions for someone who's gotten herself
into a mess?

Nicole
 
T

tina

well, there's a few ways to do it. one way is to use the OpenArgs argument
of the OpenForm action (see Help to read up on the action arguments) to
store the value of the primary key in the "main" form's current record. then
use the BeforeInsert event of the 2nd, separate form to assign the value of
OpenArgs to the new record's foreign key field, as

Me!ForeignKeyFieldname = Me.OpenArgs

hth


Nicole said:
Tina,

I am using a separate form. I already have a form that works precisely the
way I want it to. The code for that is...

Private Sub MP200_Click()
On Error GoTo Err_MP200_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MP-200 Status"

stLinkCriteria = "[Report No]=" & Me![Report No]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_MP200_Click:
Exit Sub

Err_MP200_Click:
MsgBox Err.Description
Resume Exit_MP200_Click

End Sub

********
Only thing is that I can't remember/figure out how to include"ReportNo"
auto number which comes from my main form into the table of my new form.
Also (and I know this seems irresponsible), the form for the above code
doesn't even have a table on the BE and I can't even remember how I created
it. I've always been able to back track my steps until now.

I tried to install a separate autonumber for my newest form and ran into the
issue at hand. I know I need to get the main form's autonumber onto the
table of this new form. Any suggestions for someone who's gotten herself
into a mess?

Nicole

tina said:
forms don't have Autonumbers, tables do. forget the forms for a minute; are
the parent and child *tables* properly related in the Relationships window?
if one parent record may have many related child records, but each child
record is related to only one parent record, then you have a one-to-many
relationship between the two entities (tables). each table needs its' own
primary key; plus, the primary key values of the parent records must be
stored in a *foreign* key field (with matching or compatible data type, the
name of the field doesn't matter) in the child records, so you can relate
each child record to a specific parent record.

have you done the above?

if so, then forms are next. if you have a main form bound to the parent
table, and a subform bound to the child table, then open the main form in
Design view, click on the subform control to select it, and open the
Properties box. the LinkMasterFields property should show the name of the
parent table's primary key field. the LinkChildFields property should show
the name of the child table's *foreign key* field.

if your tables are related properly, and the mainform/subform are linked
properly, as described above, then you'll get an automatic link between
parent and child records without any code.

if you're opening a *separate form* to enter the child records, then by
definition the main form is not a parent form, and the second form is not a
subform or child form - it's merely a separate form. you'll have to use code
to create the link between the record showing in the main form, and the
record(s) you review or enter in the second form. if you need help with
that, post back.

hth


and
memo the
child parent
and from
the
 
G

Guest

My main form is opened with the Switchboard Wizard, so I can't figure out how
to get to the OpenForm action of the main form. The DoCmnd, if there is one
is hidden some place where I can't see it.

Nicole
 
T

tina

i'm talking about the OpenForm action that you use to open the *second,
separate* form.

hth
 
G

Guest

Tina,

Let me just say that you are awesome, and I love you, and you are a genius.
This issue that has plagued me for days is now resolved! I've used the
following configuration of code...

In the OnClick Event of the control of the main form:

Private Sub Closeout_Project_Click()
On Error GoTo Err_Closeout_Project_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "CloseoutDocumentsCheckList"

stLinkCriteria = "[Binder ID]=" & Me![Report No]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , [Report No]

Exit_Closeout_Project_Click:
Exit Sub

Err_Closeout_Project_Click:
MsgBox Err.Description
Resume Exit_Closeout_Project_Click

End Sub

And in the BeforeInsert event of the second form:

Me![Binder Id] = Me.Open Args

Tina, you ROCK!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top