Addressing subform (1 Viewer)

kirkm

Registered User.
Local time
Today, 22:04
Joined
Oct 30, 2008
Messages
1,257
In All Access Objects Forms window, my form is called "Form1" and the subform is "qryB subform".
Then in Project Explorer window its called "Form_Form1" and no subform listed there.
I've never quite been able to figure out why the Form Name isn't the same everywhere.
Thanks.
 
Last edited:

June7

AWF VIP
Local time
Today, 01:04
Joined
Mar 9, 2014
Messages
5,425
Subform/Subreport is actually a special container control placed on form or report. This container holds a table or query or form or report. I always give container a name different from the object it holds.

A form or report might not show in the VBA Editor list if it has never had any code behind it.

VBA Editor prefixes form and report names with Form_ and Report_. I think it is a grouping strategy so like items are listed together.
 

kirkm

Registered User.
Local time
Today, 22:04
Joined
Oct 30, 2008
Messages
1,257
June I'm not following "Container" and "Object it Holds" too well. You could say the Subform/Subreport is like a control on a Form ?
But what is holds is the data, yes? What name might that have? My subform was based on a query and it called itself that query name, a space and "subform".

The Form name, will be the same but with a leading Form_ or Report_ . And may not be there unless contains some code? Got it! Thanks for explaining.
 

June7

AWF VIP
Local time
Today, 01:04
Joined
Mar 9, 2014
Messages
5,425
Subform/Subreport container control has SourceObject property. This determines what object the container "holds".

Advise not to use spaces nor punctuation/special characters (underscore is only exception) in naming convention. You will avoid a lot of headaches down the road. Suggest you not use exact same name for multiple objects. Many use a prefix and/or suffix convention: tblCustomers, frmCustomers, qryCustomers, rptCustomers.

I never use the design wizards.
 

Isaac

Lifelong Learner
Local time
Today, 02:04
Joined
Mar 14, 2017
Messages
8,738
All forms with their HasModule property = True will have a class module of their own (in the vba project window), named as prefixed by Form_
By the way, If ever you have a form without a module showing up in VBA because no code has yet been written for it, change its HasModule property to True or Yes.

All forms are forms. Calling them subform is really just a creative way of explaining that they have been dragged onto another form (and possibly have been given a relationship in the properties), but they are still a Form and will be listed with Forms, and (subject to the above information) will have their own module in vba.
 

June7

AWF VIP
Local time
Today, 01:04
Joined
Mar 9, 2014
Messages
5,425
My subform was based on a query and it called itself that query name, a space and "subform".
So how did you do this - did you highlight query and then click Create Form? Then did you drag this form onto another form? If so, this will cause a container control to be established with a SourceObject of the form and container control will have same name. End up with query, form, container all having same name. I always assign different names.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:04
Joined
Feb 19, 2002
Messages
42,981
Unless you actually create a form, you won't see any object named qryB subform. Apparently, you just put the name of a query in the name for the subform. I'm sorry Access allows this since it is pretty poor practice because you don't get any events with which you can control modifications. Access tends to bend over backwards to make things easy for novices and the result is that it supports some really bad practices including but not limited to allowing embedded spaces and special characters in object names.

Make a form the way you would normally. If I'm going to use the form as a subform, I name it sfrmXYZ so when I see the list of forms, I know which are actual forms and which are only used as subforms on some other form.

Once you create a form, you can use event code to control what updates happen and even employ security so that only certain users are allowed to perform updates.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 09:04
Joined
Jul 9, 2003
Messages
16,245
my form is called "Form1" and the subform is "qryB subform".

and no subform listed there.

Edit:-
But you mentioned a subform?

>>>"qryB subform"<<<

When you drag a query from the Navigation Pane on to a form, MS Access automatically creates a subform for you. I suspect, from the name of your subform:- "qryB subform" that this is what has happened, because that looks very much like the default name that Microsoft Access gives the subform it creates... Do you recall dragging a query on to a form? Incidentally, I agree with Pat, in that many problems are caused by Microsoft Access trying to help you!
 
Last edited:

June7

AWF VIP
Local time
Today, 01:04
Joined
Mar 9, 2014
Messages
5,425
Can't drag a table or query onto a form or report (I tried), only forms and reports.

Can drag a container control onto form or report and then set its SourceObject property to table or query.
 

June7

AWF VIP
Local time
Today, 01:04
Joined
Mar 9, 2014
Messages
5,425
Still with Access 2010. So I guess MS changed that. Now OP needs to respond.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 09:04
Joined
Jul 9, 2003
Messages
16,245
Dragging a Query or Table on to a Form - Nifty Access


If you want to see more of my Nifty Access YouTube Videos, Sign up to my YouTube Account! Uncle Gizmo on YouTube


 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:04
Joined
Feb 19, 2002
Messages
42,981
I can't drag a query onto a form either, not that I would ever want to. Access creates a subform control but it does not make the query the bound object.

Best practice as I said earlier - create a subform first. That gives you events you can use to control or prevent updating.
 

Users who are viewing this thread

Top Bottom