Error 2465 when refferring to Subform (1 Viewer)

XV1957

Registered User.
Local time
Today, 13:31
Joined
Aug 6, 2014
Messages
80
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
 

vbaInet

AWF VIP
Local time
Today, 12:31
Joined
Jan 22, 2010
Messages
26,374
Code:
[Forms]![frmCompanyNames][COLOR="Red"][B].[/B][/COLOR][frmCompanyNamesSubfrm].Form.RecordsetClone
Also ensure that you're referencing the subform control name, not the subform name.
 

XV1957

Registered User.
Local time
Today, 13:31
Joined
Aug 6, 2014
Messages
80
Thank you vbaInet.
I implemented your change and the result was that I got a different 2465 error namely "MSQccess cqn4t find the field |1 referred to in your expression.
The debugger stopped right on this statement
 

vbaInet

AWF VIP
Local time
Today, 12:31
Joined
Jan 22, 2010
Messages
26,374
Did you see my last comment about checking the subform control name?

1. In design view click anywhere outside the subform, but inside the main form
2. Click the subform once and look in the property sheet for the proper name of the subform control.

You must click it once or else you won't get the subform control, you'll get the subform.
 

XV1957

Registered User.
Local time
Today, 13:31
Joined
Aug 6, 2014
Messages
80
vbaInet,
you really made my day!
I had noticed your comment but was not aware of the difference between the name of the control and of the subform, so my checking the name did not yield the expected result.
Your help allows me to work further and build the application. I would have thrown in the towel without your help. Thanks again.
 

vbaInet

AWF VIP
Local time
Today, 12:31
Joined
Jan 22, 2010
Messages
26,374
Yes. The subform control is the control that houses the form. It's only called a subform because it's a form "embedded" in another form.

Think of the subform control like any other control. It has it's own properties and methods like a textbox does. The only difference is that it can house a form.

Now you can get back to developing ;)
 

Users who are viewing this thread

Top Bottom