I am pulling my hair out as I keep getting “ Run-time error ‘2465’: Microsoft Access can’find the field 'frmCompanyNamesSubfrm" and I am not seeing the wrong syntax.
I have a main form frmCompanyNames on which is one subform called frmCompanyNamesSubfrm . The fields on the subform come from a query with two related tables.
Both forms are a copies of two forms that worked called XVCompany2 and XVCompany2 Subform (one space in the name).
I changed the subform XVCompany2 Subform to arrange it from a Datasheet to a Continuous Form looking like a Datasheet, and give it the the name frmCompanyNamesSubfrm. I took the original subform out of the copied main form and dragged the new subform into this copy. The main form was not changed, apart from replacing the subform.
In the code for the on-click event of a command button on the main form frmCompanyNames nothing changed except of course the subform name had to be changed.
I keep getting the error 2465 in the following cases:
1. When I copy the code from the original form to the new form with no other change than the appropriate name change for the subform. Checking with the find command yielded no typing error. [frmCompanyNamesSubfrm].SetFocus is where the debugger stops. In the original code this statement said [XVCompany-Person Subform2].SetFocus and never caused a problem.
2. when I try [expressions like
a. set rstClone = [Forms]![frmCompanyNames]![frmCompanyNamesSubfrm].Form.RecordsetClone
b. set rstClone = Forms.frmCompanyNames!frmCompanyNamesSubform.Form.RecordsetClone
c. set rstClone = Me.[frmCompanyNames]![frmCompanyNamesSubform].Form.RecordsetClone
and any other variation with or witout square brackets,and with or without the last Form in the statement.
What am I not seeing or doing incorrectly? Thanks in advance for any hint.
Here is the original code with only the form names changed. It may not be the nicest, but it worked previously.
Private Sub BtnComm_Click()
Dim db As Database
Set db = CurrentDb
Dim rst As Recordset
Set rst = db.OpenRecordset("Communication", dbOpenDynaset )
Me!ID.Enabled = True
Me!ID.SetFocus
GlCompID = ID.Value
Me!ID.Enabled = False
[frmCompanyNamesSubfrm].SetFocus
GLPersID = Me![frmCompanyNamesSubfrm].Form.PersKey
With rst
.FindFirst "[CompID] like " & GlCompID & "And PersID = " & Me![frmCompanyNamesSubfrm].Form.PersKey
If .NoMatch Then
MsgBox "No communication for this person"
Else
DoCmd.OpenForm "frmQryAllComsPerCompPers", , , "CompID = " & GlCompID & "And PersID = " & Me![frmCompanyNamesSubfrm].Form.PersKey, acFormEdit
DoCmd.SetOrderBy "ID Desc"
End If
End With
Set rst = Nothing
db.Close
Set db = Nothing
End Sub
I have a main form frmCompanyNames on which is one subform called frmCompanyNamesSubfrm . The fields on the subform come from a query with two related tables.
Both forms are a copies of two forms that worked called XVCompany2 and XVCompany2 Subform (one space in the name).
I changed the subform XVCompany2 Subform to arrange it from a Datasheet to a Continuous Form looking like a Datasheet, and give it the the name frmCompanyNamesSubfrm. I took the original subform out of the copied main form and dragged the new subform into this copy. The main form was not changed, apart from replacing the subform.
In the code for the on-click event of a command button on the main form frmCompanyNames nothing changed except of course the subform name had to be changed.
I keep getting the error 2465 in the following cases:
1. When I copy the code from the original form to the new form with no other change than the appropriate name change for the subform. Checking with the find command yielded no typing error. [frmCompanyNamesSubfrm].SetFocus is where the debugger stops. In the original code this statement said [XVCompany-Person Subform2].SetFocus and never caused a problem.
2. when I try [expressions like
a. set rstClone = [Forms]![frmCompanyNames]![frmCompanyNamesSubfrm].Form.RecordsetClone
b. set rstClone = Forms.frmCompanyNames!frmCompanyNamesSubform.Form.RecordsetClone
c. set rstClone = Me.[frmCompanyNames]![frmCompanyNamesSubform].Form.RecordsetClone
and any other variation with or witout square brackets,and with or without the last Form in the statement.
What am I not seeing or doing incorrectly? Thanks in advance for any hint.
Here is the original code with only the form names changed. It may not be the nicest, but it worked previously.
Private Sub BtnComm_Click()
Dim db As Database
Set db = CurrentDb
Dim rst As Recordset
Set rst = db.OpenRecordset("Communication", dbOpenDynaset )
Me!ID.Enabled = True
Me!ID.SetFocus
GlCompID = ID.Value
Me!ID.Enabled = False
[frmCompanyNamesSubfrm].SetFocus
GLPersID = Me![frmCompanyNamesSubfrm].Form.PersKey
With rst
.FindFirst "[CompID] like " & GlCompID & "And PersID = " & Me![frmCompanyNamesSubfrm].Form.PersKey
If .NoMatch Then
MsgBox "No communication for this person"
Else
DoCmd.OpenForm "frmQryAllComsPerCompPers", , , "CompID = " & GlCompID & "And PersID = " & Me![frmCompanyNamesSubfrm].Form.PersKey, acFormEdit
DoCmd.SetOrderBy "ID Desc"
End If
End With
Set rst = Nothing
db.Close
Set db = Nothing
End Sub