Like all MS products, Access tries to be too clever and figure out what you
meant for you. Sometimes this does what you intend; other times it does not.
In this case, fsbu_Listings is the name of a subform *control*. That control
may contain a form (or it may not if SourceObject is blank, and the form may
or may not have the same name as the subform control. To see the difference,
open the form in design view, open the Immediate Window (Ctrl+G), and enter:
? TypeName(Forms!Form1!fsub_Listings)
substituting your main form name for Form1.
It will tell you that this is a control of type Subform.
Then try:
? TypeName(Forms!Form1!fsub_Listings.Form)
It will tell you that this is a class of type Form_fsub_Listings.
That is, you are referring to the form in the subform control, as distinct
from the subform control.
Another way to see the difference is to try:
? Forms!Form1!fsub_Listings.Properties.Count
It will tell you a subform control has around 50 properties.
? Forms!Form1!fsub_Listings.Form.Properties.Count
This time it tells you a form has over 200 properties.
If you really want to take this further, try:
? TypeName(Forms!Form1!fsub_Listings.Form.ListingID)
? TypeName(Forms!Form1!fsub_Listings!ListingID)
They appear to be the same, so ask if they are the same thing:
? Forms!Form1!fsub_Listings.Form.ListingID Is
Forms!Form1!fsub_Listings!ListingID
It's true: they identical ways of referring the the control in the subform.
Now try:
? TypeName(Forms!Form1!fsub_Listings.ListingID)
That will probably error: you cannot use the dot like that (without the
..Form part), but you can use the bang.
So which should you use? Over the years, there's been a great deal of
discussion of bang verses dot and the difference between them.
Unfortunately, even the most respected Access books have got this wrong and
given faulty explanations and rules-of-thumb. The best explanation I can
suggest is this one by Andy Baron:
http://my.advisor.com/articles.nsf/aid/05352
Beyond that (and ignoring the .Form part for now), the ProductCode in this
line:
If ProductCode = "xyz" Then
could be interpreted as any of these:
a) a control (e.g. text box) named ProductCode.
b) a field in the form's Fields (even if there is no control by that name)
c) a property or method of the form (not built-in)
d) a variable or constant declared in the form's module
e) an undeclared variable or constant in the code
f) a global name in Access itself.
In this particular case, (f) is very likely.
If you don't know what I mean, just open the Immediate Window and enter:
? ProductCode
(It's actually a member of the Access Application object.)
That's just an illustration of why it's important to use the narrowest
reference you can. Include the "Me" in your code. Include the .Form. And be
very clear about whether you are referring to a control on the form, or a
field in the form's RecordSource: they are different.
Hope that's helpful without being too much.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
Max Moor said:
[fsub_Listings].Form![ListingID]
Hi Allen,
I tried it, but to no avail.
I have another question, though. In the text box, I was initially
advised to use '[fsub_Listings].Form![ListingID]' as the control source to
"link' it to the 1st subform.
I found that '[fsub_Listings]![ListingID]' works as well. What is the
difference with or without the '.Form'?
Max