G
Guest
I have a main form and a subform1. The subform1 has a command button that
opens Form2.
Main Form
MainID(PK)
SubForm1ID (FK)
MainFormInfo
txtInstructionsID - Control Source: =[Subform1].[Form]![Subform1ID]
Subform1
Subform1ID (PK)
MainID (FK)
Form2ID (FK)
Subform1Info
Form2
Form2ID (PK)
Subfrom1ID (FK)
Form2Info
This is the code behind the command button on Subform1:
Private Sub cmdbtnOpenForm2_Click()
On Error GoTo Err_cmdbtnOpenForm2_Click
Dim strLinkCriteria As String
Dim strDocName As String
strDocName = "Form2"
' If Subform1ID control is blank, display a message.
If IsNull(Me![Subform1ID]) Then
Me![Form2].SetFocus
Else
strDocName = "Form2"
strLinkCriteria = "[Subform1ID] = " & Me![Subform1ID]
DoCmd.OpenForm strDocName, , , strLinkCriteria, acFormAdd
End If
Exit_cmdbtnOpenForm2_Click:
Exit Sub
Err_cmdbtnOpenForm2_Click:
MsgBox Err.Description
Resume Exit_cmdbtnOpenForm2_Click
End Sub
On the main form, I have an unbound text field (txtInstructionsID) with the
control source: =[Subfrm1].[Form]![Subform1ID]
Subform1
Link Child Field: Subform1ID
Link Master Field: Subform1ID
Form2
Link Child Field:Suform1ID
Link Master Field: txtInstructionsID
I have FINALLY been able to open Form2 to show the pertinent record based on
the Subform1ID. But, when I go to add a new record to Form2, it doesn't let
me add anything. What am I doing wrong?
opens Form2.
Main Form
MainID(PK)
SubForm1ID (FK)
MainFormInfo
txtInstructionsID - Control Source: =[Subform1].[Form]![Subform1ID]
Subform1
Subform1ID (PK)
MainID (FK)
Form2ID (FK)
Subform1Info
Form2
Form2ID (PK)
Subfrom1ID (FK)
Form2Info
This is the code behind the command button on Subform1:
Private Sub cmdbtnOpenForm2_Click()
On Error GoTo Err_cmdbtnOpenForm2_Click
Dim strLinkCriteria As String
Dim strDocName As String
strDocName = "Form2"
' If Subform1ID control is blank, display a message.
If IsNull(Me![Subform1ID]) Then
Me![Form2].SetFocus
Else
strDocName = "Form2"
strLinkCriteria = "[Subform1ID] = " & Me![Subform1ID]
DoCmd.OpenForm strDocName, , , strLinkCriteria, acFormAdd
End If
Exit_cmdbtnOpenForm2_Click:
Exit Sub
Err_cmdbtnOpenForm2_Click:
MsgBox Err.Description
Resume Exit_cmdbtnOpenForm2_Click
End Sub
On the main form, I have an unbound text field (txtInstructionsID) with the
control source: =[Subfrm1].[Form]![Subform1ID]
Subform1
Link Child Field: Subform1ID
Link Master Field: Subform1ID
Form2
Link Child Field:Suform1ID
Link Master Field: txtInstructionsID
I have FINALLY been able to open Form2 to show the pertinent record based on
the Subform1ID. But, when I go to add a new record to Form2, it doesn't let
me add anything. What am I doing wrong?