problem opening form

S

sue gray

I have a main form that has a command button to open a form in data entry
mode. The form I am opening has entry fields at the top of the form and 4
subforms - set up as pages in the middle.

My tables are tblclient, with clientid as primary key and autonumbered. and
tbltxplanmh with txplanMHID as primary key and autonumbered. clientid is a
foreign key in tbltxplanmh.

The problem I am having is when I click the command button the form opens in
entry mode and I can fill out the top entry fields, but the subforms (pages)
are blank boxes.

I have given as much info as I can think of, I hope I haven't confused
anyone too much. Thanks for any help. HEre's the command button code:


Private Sub AddTxPlan_MH_Click()
' This code adds a new tx plan based on client id.
On Error GoTo Err_AddTxPlan_MH_Click

Dim strDocName As String

strDocName = "frmTxPlanMH"

DoCmd.OpenForm strDocName, , , , acAdd, , Me!clientid

If IsNull(Forms!frmtxplanmh!clientid) Then
Forms!frmtxplanmh!clientid = Me!clientid
Forms!frmtxplanmh!ContactType.SetFocus
End If


Exit_AddTxPlan_MH_Click:
Exit Sub

Err_AddTxPlan_MH_Click:
MsgBox Err.Description
Resume Exit_AddTxPlan_MH_Click

End Sub
 
M

Marshall Barton

sue said:
I have a main form that has a command button to open a form in data entry
mode. The form I am opening has entry fields at the top of the form and 4
subforms - set up as pages in the middle.

My tables are tblclient, with clientid as primary key and autonumbered. and
tbltxplanmh with txplanMHID as primary key and autonumbered. clientid is a
foreign key in tbltxplanmh.

The problem I am having is when I click the command button the form opens in
entry mode and I can fill out the top entry fields, but the subforms (pages)
are blank boxes.

I have given as much info as I can think of, I hope I haven't confused
anyone too much. Thanks for any help. HEre's the command button code:


Private Sub AddTxPlan_MH_Click()
' This code adds a new tx plan based on client id.
On Error GoTo Err_AddTxPlan_MH_Click

Dim strDocName As String

strDocName = "frmTxPlanMH"

DoCmd.OpenForm strDocName, , , , acAdd, , Me!clientid

If IsNull(Forms!frmtxplanmh!clientid) Then
Forms!frmtxplanmh!clientid = Me!clientid
Forms!frmtxplanmh!ContactType.SetFocus
End If


Make sure the subform control's Link Master/Child properties
are set to the ClientID field.

You have probably alreasy done that, so I also think you
chould set the ClientID in the form's Load event instead of
in the calling form. This should be easy since you are
already passing the ClientID in OpenArgs:

If IsNull(Me!clientid) Then
Me!clientid = Me.OpenArgs
Me!ContactType.SetFocus
End If
 
J

JonWayn

There are 3 properties that you have to set for each subform control:
1. SourceObject: this tells your main form whose form's data to display
in the subform control.

2. LinkMasterFields: this tells which field in the main form relates to
the subform

3. LinkChildFields: tells which subform field relates to the linked
master field

These are all found on the Data tab of the property sheet.

So, for instance: Set SourceObject to the name of the subform in question
(this is not necessarily the same as the name of the subformcontrol - this is
the name of the form feeding the subform control). your main form has a
txplanMHID field, set LinkMasterFields to txplanMHID. If the subform foreign
field corresponding to this field is ClientID, then set LinkChildFields to
ClientID. And





===================================================
 

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