Solved Referencing a sub sub control (1 Viewer)

ClaraBarton

Registered User.
Local time
Today, 04:11
Joined
Oct 14, 2019
Messages
479
All of these controls work except for the Authors (line 20) and Subjects Line 70). These both throw an error 2455.
  • I've removed the bangs and replaced with dots.
  • I've made sure the names are not the same as the record source names.
  • I've made sure the headers on the Authors and Subject subcontrols are not visible.
Is there something I'm missing?
Code:
      Dim ctlAuthor As control
      Dim ctlIllustrator As control
      Dim ctlPublisher As control
      Dim ctlSeries As control
      Dim ctlStatus As control
      Dim ctlSubject As control
'20    Set ctlAuthor = Me!BookDetail.Form!Authors.Form!btnClear
30    Set ctlIllustrator = Me!BookDetail.Form!btnClearIllustrator
40    Set ctlPublisher = Me!BookDetail.Form!btnClearPublisher
50    Set ctlSeries = Me!BookDetail.Form!btnClearSeries
60    Set ctlStatus = Me!BookDetail.Form!btnClearStatus
70    Set ctlSubject = Me!BookDetail.Form!Subjects.Form!btnClear
1679850653116.png
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:11
Joined
May 21, 2018
Messages
8,555
Most likely is the name of the sub subform control. Obviously BookDetail is correct. My guess the sub-subforms are not called Authors, and not called Subjects. Click on the outside and check.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:11
Joined
May 21, 2018
Messages
8,555
I looked at an old version and they are called fSubAuthors and SubSubjects.
 

ClaraBarton

Registered User.
Local time
Today, 04:11
Joined
Oct 14, 2019
Messages
479
I looked at an old version and they are called fSubAuthors and SubSubjects.
please... this form has traveled many miles from the old one!;) I renamed them. They are right. Actually, I renamed them to Authors and Subjects to change from the recordsource. Before I renamed them it was the same error.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:11
Joined
May 21, 2018
Messages
8,555
Does not look like a problem with the referencing, if the names are correct. That error does suggest the subform control is correct, but the source object is not loaded. (Invalide reference to form property)
Where is the run? This can be a timing thing. When this code is run can you verify that the sub subforms are loaded. If there are no linked records at the time then the sub-subform may not be loaded.

Try this to help error check. It is a little clearer.
Code:
Dim   btnAuthor As CommandButton
Dim   btnIllustrator As CommandButton
Dim   btnPublisher As CommandButton
Dim   btnSeries As CommandButton
Dim   btnStatus As CommandButton
Dim   btnSubject As CommandButton
Dim   sfrmDetail as access.form
dim   ssFrmAuthors as access.form
dim   ssFrmSubjects as access.form

set sfrmDetail = me.bookDetail.form
set ssFrmAuthors = sFrmDetail.Authors.form
set ssFrmSubjects = sFrmDetail.Subjects.Form

set btnIllustrator = sFrmDetail.btnClearIllustrator
Set btnPublisher = sFrmDetail.btnClearPublisher
Set btnSeries = sFrmDetail.btnClearSeries
Set btnStatus = sFrmDetail.BtnClearStatus

Set btnAuthor = ssFrmAuthors.btnClear
Set btnSubject = ssFrmSubjects.btnClear

If this is a case where you are assigning the control before the form is loaded then I would likely have to see the db to recommend a solution. Likely you will have to assign it in a later event.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:11
Joined
May 21, 2018
Messages
8,555
Even better would be to dimension your subforms using the real form name class (as shown in the object browser)
Code:
Dim   sfrmDetail as Form_FrmDetail
dim   ssFrmAuthors as Form_FrmAuthors
dim   ssFrmSubjects as Form_FrmSubjects

where the real name of the form is proceeded by Form
Form_YourFormName

This will ensure intellisense works for all objects referenced.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:11
Joined
May 21, 2018
Messages
8,555
Again that is one or two things. Either you are wrong and Authors is not a control (subform) name of lstSubDetail or the subform control does not have a form loaded at the time you try to set it. Triple check the name of the subform control (not the name of the subform).
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:11
Joined
May 21, 2018
Messages
8,555
To further error check you could do this

Code:
....
dim   scAuthors as access.subform

set sfrmDetail = me.bookDetail.form
set scAuthors = sfrmDetail.Authors
set ssFrmAuthors = scAuthors.form

if scAuthors fails then you do not have a subform control named authors
if
ssFrmAuthors fails then the form is not loaded.
 

ClaraBarton

Registered User.
Local time
Today, 04:11
Joined
Oct 14, 2019
Messages
479
So the form isn't loaded?
View attachment 107156
Where do I go from here?
So... The detail form isn't filled until a book is selected in Books. So you're right, it isn't there. I'm using the option number on the form. Does that mean this code should be located on the detail form? Well, duh. of course. I'll go back to the drawing board... Thank you so much for your help.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:11
Joined
May 21, 2018
Messages
8,555
So that tells me that your subform control is called authors and you can reference it. You cannot get a reference to the form property. Unless I am missing something your sub form lstSubAuthors is not loaded at this time. So you have a subform control, but nothing is in it when you call it. I think this can happen when the subform is set to allow additions to false and no records are returned.
 

Users who are viewing this thread

Top Bottom