Passing an autonumber field to the subform

C

Cindy

I have a form that has an autonumber (primary key) field that I want to pass
to the subform when it opens (togglekey). What do I need to do to make this
happen?
 
D

Duane Hookom

What do you mean by "pass to the subform"? Is it possible you can use the
Link Master/Child properties to automatically populate foreign key values in
the subform?
 
C

Cindy

I'm sure it is, but I don't remember how to do that, and can't kind where it
is. Can you walk me through it?
 
D

Duane Hookom

Set the Link Master/Child properties of the subform control to the field
names you want to pass from the main form to the subform.
 
V

Van T. Dinh

Open the Main Form in DesignView, click somewhere on the Subform or the
rectangle enclosing the Subform. You should see the sizing handlers (little
squares) round the Subform. Open the Properties window and in the "Data"
tab, you should see the LinkChildFields / LinkMasterFields Properties.

In the usual set-up, the PK Field in the parent Table (RecordSource for the
Main Form) is used as the LinkMasterFields and the FK in the child Table
(RecordSource for the Subform) as the LinkChildFields.
 
J

John Vinson

I have a form that has an autonumber (primary key) field that I want to pass
to the subform when it opens (togglekey). What do I need to do to make this
happen?

It sounds like you have code which opens a *separate, independent*
form - rather than using a Subform control. Is that correct? Have you
intentionally chosen not to use a Subform?

John W. Vinson[MVP]
 
C

Cindy

No. How do I check for that?

John Vinson said:
It sounds like you have code which opens a *separate, independent*
form - rather than using a Subform control. Is that correct? Have you
intentionally chosen not to use a Subform?

John W. Vinson[MVP]
 
J

John Vinson

No. How do I check for that?

A Subform is one of the types of controls in the form design toolbar.
It's a box on a main form which contains another form; the Subform
Control has "master link field" and "child link field" properties
which keep the two forms' recordsources in synch.

If you have a command button (you say a "toggle"???) which is opening
another form, then you are NOT using a subform. It's possible to keep
two forms opened in this way in synch, but it requires writing a lot
of code, and it's probably less convenient for the user.

I cannot see your form, so I don't know how you have set it up... you
can tell more easily than we can!

John W. Vinson[MVP]
 
C

Cindy

You are correct. I should have been calling it a linked form not a subform.
It is a "togglelink" button that connects the 2 forms.

What can I do to pass the autonumber field to the linked form?
 
J

John Vinson

You are correct. I should have been calling it a linked form not a subform.
It is a "togglelink" button that connects the 2 forms.

I am not familiar with a "togglelink" control - it's not a term
defined in Access. Could you post the code which "connects" the two
forms?
What can I do to pass the autonumber field to the linked form?

That depends on what your code is doing... which I cannot see.

John W. Vinson[MVP]
 
C

Cindy

Thanks for your help. Togglelink is the default name Access gives the
button. Here is the current "event procedure"

Sub Form_Current()
On Error GoTo Form_Current_Err

If ChildFormIsOpen() Then FilterChildForm

Form_Current_Exit:
Exit Sub

Form_Current_Err:
MsgBox Error$
Resume Form_Current_Exit

End Sub
Sub ToggleLink_Click()
On Error GoTo ToggleLink_Click_Err

If ChildFormIsOpen() Then
CloseChildForm
Else
OpenChildForm
FilterChildForm
End If

ToggleLink_Click_Exit:
Exit Sub

ToggleLink_Click_Err:
MsgBox Error$
Resume ToggleLink_Click_Exit

End Sub
Private Sub FilterChildForm()

If Me.NewRecord Then
Forms![Resume].DataEntry = True
Else
Forms![Resume].Filter = "[Candidate ID] = " & Me.[Candidate ID]
Forms![Resume].FilterOn = True
End If

End Sub
Private Sub OpenChildForm()

DoCmd.OpenForm "Resume"
If Not Me.[ToggleLink] Then Me![ToggleLink] = True

End Sub
Private Sub CloseChildForm()

DoCmd.Close acForm, "Resume"
If Me![ToggleLink] Then Me![ToggleLink] = False

End Sub
Private Function ChildFormIsOpen()

ChildFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "Resume") And
acObjStateOpen) <> False

End Function
 
C

Cindy

Thanks for the help. I got it to work.

Cindy said:
Thanks for your help. Togglelink is the default name Access gives the
button. Here is the current "event procedure"

Sub Form_Current()
On Error GoTo Form_Current_Err

If ChildFormIsOpen() Then FilterChildForm

Form_Current_Exit:
Exit Sub

Form_Current_Err:
MsgBox Error$
Resume Form_Current_Exit

End Sub
Sub ToggleLink_Click()
On Error GoTo ToggleLink_Click_Err

If ChildFormIsOpen() Then
CloseChildForm
Else
OpenChildForm
FilterChildForm
End If

ToggleLink_Click_Exit:
Exit Sub

ToggleLink_Click_Err:
MsgBox Error$
Resume ToggleLink_Click_Exit

End Sub
Private Sub FilterChildForm()

If Me.NewRecord Then
Forms![Resume].DataEntry = True
Else
Forms![Resume].Filter = "[Candidate ID] = " & Me.[Candidate ID]
Forms![Resume].FilterOn = True
End If

End Sub
Private Sub OpenChildForm()

DoCmd.OpenForm "Resume"
If Not Me.[ToggleLink] Then Me![ToggleLink] = True

End Sub
Private Sub CloseChildForm()

DoCmd.Close acForm, "Resume"
If Me![ToggleLink] Then Me![ToggleLink] = False

End Sub
Private Function ChildFormIsOpen()

ChildFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "Resume") And
acObjStateOpen) <> False

End Function




John Vinson said:
I am not familiar with a "togglelink" control - it's not a term
defined in Access. Could you post the code which "connects" the two
forms?


That depends on what your code is doing... which I cannot see.

John W. Vinson[MVP]
 
Top