Accessing a subform on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

FRom subform POS_Q1 on Form POS_Aids1 I open up a form POS_DelAdr in a new
window
On the click event of POS_DelAdr I want to then set some values back on the
subform POS_Q1

I have the following on the POS_DelAdr click event
Dim frmCalling as Form
frmCalling = Forms("POS_Aids1!POS_Q1")

I have tried
frmCalling = Forms("POS_Aids1.POS_Q1")

It doesn't like the POS_Q1 bit

I am sure it is simple and I'm just having a mental block!
Any clues please?
Stephen English
 
It is important to realize that a sub form is in fact, just a control.

You can actually place 5 sub-form controls on a form, and all of the forms
CAN BE THE SAME form.

That means, that you in fact have 5 copies of the same sub-form displayed.
So, when you reference the form, which of the 5 copies of the sub-forms are
you referencing? (I just pointing hits out, since this is perfectly a legal
thing to do!!).

Thus, it is also important to note that you use the sub-form control NAME,
not the name of the actual form you used in the sub form.

Hence, the way you reference the sub-form is to reference the control,a nd
then what is called the "form" property of that control.

Hence, you could use:


forms!YourFormName!SubForm.Form!City

Note that in the above, we use the name of the contorl you placed on thne
form, NOT the actaul sub-form name. It turn out that most of the time we do
use the same name for the contorl as the sub-form name...but you don't have
to.

So, in effect, the syntax is:

forms!YourFormName!YourSubFormContorl.Form!City

The above would thus refernces the city field in the sub form (in this
example SubFormContorl).

So, in your case:

Dim frmCalling as Form

set frmCalling = forms!TheMainFormName!POS_Aids1.Form

you are now freeto set any value in the sub form, like:

frmCalling!FirstName = "Albert"
 
I had a similar question three days ago that did not get answered, but mine
was more complicated I suppose. Regardless, the following would have helped
me if I had found it before I found the answer elsewhere:

Referring to Controls on a Subform
http://members.iinet.net.au/~allenbrowne/casu-04.html

In the Access documentation, look for the SubForm Object. I think the
specific place in the documentation that helped me was the page titled "Call
Procedures in a Subform or Subreport". Eventhough it is about procedures, it
helped me to figure out how to access controls in a form in a subform.
 
It is quite interesting that my question three days ago did not get an
answer, although the following is an answer to my question also. My
question, I thought, was more complete, but perhaps it was too complete (too
much). For what it is worth, I would have been helped with a lot less that
what is in this answer.
 
Sam Hobbs said:
It is quite interesting that my question three days ago did not get an
answer, although the following is an answer to my question also. My
question, I thought, was more complete, but perhaps it was too complete
(too much). For what it is worth, I would have been helped with a lot less
that what is in this answer.

Hum, I my self did not see that question...and perhaps was busy that day.
sometimes, getting a answer is going to be based on timing.

However, I just took a look...and, yes..I think the "additional" information
was the source of confusing here. You had all kinds of info about
on-current, and a few other things. That did not help. In addition, I still
somewhat confused by:
does not exist as a table or query. So using the.....

Hum? If no data for the second subform don't exist in a table, then this is
defiantly somewhat confusing. Further, if there is no data..then why is a
sub-form being used here?? So, yea..this is somewhat confusing here, as even
now I am not at all sure why a sub-form is being used to display data that
don't exist???

Of course, there is also the issue of terminology here. A form, or a control
that is not data bound is considered a un-bound form, or a un-bound control.
This seems to be what you are getting at in the above statement. And, stuff
about on-current, c++ and the rest likely scared everyone away, or was
simply too much information (I am not really sure here why your question was
missed!). Perhaps the whole question could have been:

What is the syntax to reference a control on a sub-frm?

Also note that in fact a form is a class object, and any function you put in
a form (declared as public) actually becomes a method of the form. And, to
further this, you are allowed multiple instances of that form. My comments
about the sub-form controls all having the "same" sub-form specified shows
this concept. In addition, you can in fact you can have multiple instances
of any form opened, and this multiple instances ability does not necessarily
apply to sub-forms. You can also declare and add custom properties to those
forms via

Public Property LET

And

Public Property GET
 
I did not want to be critical or sarcastic. I tired to withhold the
frustration I felt. I am sorry if my comments were not productive. I do want
to know what I could and should do better.
Hum, I my self did not see that question...and perhaps was busy that day.
sometimes, getting a answer is going to be based on timing.

Then I assume this is not the first time that a question is unanswered due
to timing. Has that problem been discussed? What are the solutions? Should I
repost after a specified amount of time?
However, I just took a look...and, yes..I think the "additional"
information was the source of confusing here. You had all kinds of info
about on-current, and a few other things. That did not help.

I really, really, really would appreciate knowing when my questions are too
thorough. I have seen many thousands (I am not exagerating) of questions in
another forum, and I am frustrated by vague questions. When I do see a vague
question, I ask for clarification. When I see a question that has a lot of
details but is still vague due to an absence of the important information, I
ask for clarification. So when I asked my question, I wanted to be as
complete as possible. It helps me to know that I should not be that
complete.
In addition, I still somewhat confused by:

does not exist as a table or query. So using the.....

Hum? If no data for the second subform don't exist in a table, then this
is defiantly somewhat confusing. Further, if there is no data..then why is
a sub-form being used here?? So, yea..this is somewhat confusing here, as
even now I am not at all sure why a sub-form is being used to display data
that don't exist???

"defiantly"? I'm sorry!

You say I provided too much. Are you now saying I did not provide enough? Or
am I just confused? I am sorry for sounding critical, but I don't
understand. I really thought I made my question extremely clear by asking a
very specific question about the Northwind Sample as a sample.

I have learned that it is a really big help to have a small and
self-contained peice of code that reproduces a problem. The Northwind Sample
was a very convenient simple sample. People should understand that a
self-contained peice of code often seems useless. Sample programs often seem
useless.

I am sorry that you think my problem is useless. If that is the reason you
did not answer my question, then I aprreciate being told. I hope that is not
the reason no one else answered the question. If you need more details about
why I am doing what I am doing, then just say so, especially if it is
relevant to the answer.
Of course, there is also the issue of terminology here. A form, or a
control that is not data bound is considered a un-bound form, or a
un-bound control. This seems to be what you are getting at in the above
statement.

Actually, isn't it a subform that is the control? Or am I still confused? It
seems that the fact that a subform is a control is part of the answer I was
looking for. It is the ".Form" part that I needed to know about.

Actually, I was quite close to an answer, and it is likely that I did try
something that would have worked except I had the problem that the initial
OnCurrent event does not work even when a solution does work otherwise. So I
probably would have been helped by knowing that I was close; that what I had
was close. Perhaps it would have helped me isolate the real problem.
And, stuff about on-current, c++ and the rest likely scared everyone away,
or was simply too much information

Perhaps the C++ was too much. I really meant for it to be separate and
independent.

(I am not really sure here why your question was
missed!). Perhaps the whole question could have been:

What is the syntax to reference a control on a sub-frm?

I suppose the answer will remain a mystery. I am not sure what I should have
done to make it more likely to get answers. The problem with leaving out the
"Northwind Sample" in the initial question is something I will certainly
avoid. I need to be careful about being distracted by such things as a cat
and my sick father.

I do know that the more time that is put into asking a quetion, the more
likely there will be a useful answer or answers. I should have put more time
into asking my question, but then I notice that the question that did get
answered seems to have been asked more hastily than mine.
Also note that in fact a form is a class object, and any function you put
in a form (declared as public) actually becomes a method of the form.

Perhaps that is all of a hint that I need. Perhaps I had already answered my
question myself but just had not thought it through. I need to think about
it some more. However yes, that part of my question was sure vague.
My comments about the sub-form controls all having the "same" sub-form
specified shows this concept. In addition, you can in fact you can have
multiple instances of any form opened, and this multiple instances ability
does not necessarily apply to sub-forms. You can also declare and add
custom properties to those forms via

Public Property LET

And

Public Property GET

This might help also. However I will create a new discussion with an
appropriate subject for discussing this. There are some fundamental
differences that I am still unclear about, but I need to think about my
situation and to better understand the relevance of the use of classes.
 
Sam
Be mighty glad that
a) Microsoft and others provide such forums
b) That many experts give up huge amounts of time to answer many questions
all on a voluntary basis
c) You often get an answer in an hour or two - in the old days you used to
hang on the line waiting for Microsoft's advice service for almost as long
and it cost us money
d) any questions get answered.

If all else fails, try rephrasing your question on a Google search.
An attitude of gratitude is what is needed here - if not you might have to
change your name to get anything answered.
Regards
Stephen English
 
I have also spent many hours voluntarily helping others; not in this
newsgroup, but in other newsgroups and in another forum. I do appreciate the
help. I do want to get as much as I can get and need. I am trying to
understand how I can do better.

I really think this lecture is not necessary. I really want to know why some
questions are ignored. I am sorry if I have offended you or said anything
unreasonable. I am sorry that my attempt to understand seems like criticism.

Note that you were critical of me for wanting to do what I wanted to do and
I responded to the criticism. I really think that any criticism I made was a
response to your criticism. It is the criticism that I don't appreciate.
People must expect that a response to a criticism will be critical.
 
I did not want to be critical or sarcastic. I tired to withhold the
frustration I felt. I am sorry if my comments were not productive. I do
want to know what I could and should do better.

Ah, gee...no problem at all here! I think you did just fine!
Then I assume this is not the first time that a question is unanswered due
to timing. Has that problem been discussed? What are the solutions? Should
I repost after a specified amount of time?

Actually, yes...if after a day or two..it is certainly consider ok to re
post. And, you can even feel free to include:

Repost: said:
I really, really, really would appreciate knowing when my questions are
too thorough.

That is kind of a how big of a ball of string type question . I really don't
have the answer here. However, there is a good faq on how to get
your questions answer here:
http://www.mvps.org/access/netiquette.htm


It has got some good ideas. I mean, this whole newsgroup thing is a
volunteer type thing, and I guess some questions get overlooked,
or by passed. I made some comments about some
extras stuff in your post, but not really a big deal here...is it?
You say I provided too much. Are you now saying I did not provide enough?
Or am I just confused? I am sorry for sounding critical, but I don't
understand. I really thought I made my question extremely clear by asking
a very specific question about the Northwind Sample as a sample.

Nah, again, not a big deal here. The only thing I mentioned here is that you
"seem" to be hinting that you are using a using a sub-form with no data. So,
the correct term we use here is a un-bound control, or un-bound form. So,
all I am stating here is that the "general" term used in these cases is
un-bound. (and hey, now we know a new term "un-bound" to use in these
cases). Your explain of using a form with no data, or no table *likely*
means
the same thing. However, as mentioned, it really don't make a difference to
answer ...does it? So, again, my only point is that you likely could have
left out the issue of un-bound form...and it would have made little, or no
difference to the answer? I can turn this question around very easily: Why
is
a bound, or un-bound form relevant to how you set, or get a value from a
control on a sub form? So, it is not a question of too much, or too little
information..it was questions of how relevant the information was to the
answer? I don't think that a bound, or un-bound form really changes your
answer here...does it? (maybe it does...but right now don't see how it
would...and thus the information was not needed). So, no issue of
too much, or too little.
If you need more details
about why I am doing what I am doing, then just say so, especially if it
is relevant to the answer.

Actually, that is exactly why I asked the question:

"Further, if there is no data..then why is a
sub-form being used here?? "

So, in fact, I did ask for more clarification here, since there are in fact
some issues that arise when using a un-bound form. And, even more issues
arise if you actually set the data souce of a form at rutnime. This would
mean that the form starts out un-bound..but becomes bound.

However, all in all...at the end of the day...I don't see any real "big"
problems with your orignal post...
 
Thank thank you, thank you. You are sure reasonable and helpful.

I do feel guilty about hijacking Stephen's thread (or discussion or whatever
we are calling it).


Albert D. Kallal said:
Actually, yes...if after a day or two..it is certainly consider ok to re
post. And, you can even feel free to include:

Repost: <your original subject goes here>


Thank you. I do try to behave and I was not sure if reposting or things like
that would be a problem. It's easy enough to do and I don't intend to overdo
it.
That is kind of a how big of a ball of string type question . I really
don't
have the answer here. However, there is a good faq on how to get
your questions answer here:
http://www.mvps.org/access/netiquette.htm

I have seen something similar and have referred othrs to the other one. I am
very tempted to start something similar about how to answer questions; I
have answered enough questions to be able to start something, but not finish
it, if you know what I mean.
It has got some good ideas. I mean, this whole newsgroup thing is a
volunteer type thing, and I guess some questions get overlooked,
or by passed. I made some comments about some
extras stuff in your post, but not really a big deal here...is it?

Yes, it is a volunteer type thing. I know that among the thousands of posts
I have made trying to help others, I sure missed being appreciated. I do try
to let others know when they do help.

My intent was to identify a problem in case there is something better that
could be done. I am sorry if I did that the wrong way.
you
"seem" to be hinting that you are using a using a sub-form with no data.
So,
the correct term we use here is a un-bound control, or un-bound form. So,
all I am stating here is that the "general" term used in these cases is
un-bound. (and hey, now we know a new term "un-bound" to use in these
cases). Your explain of using a form with no data, or no table *likely*
means the same thing.

Use of commonly understood terminology is important. As you do understand, I
have not discussed Access enough to know what is most likely to be
understood. That is one reason to provide a more lengthy explanation.

The second subform will definitely have data, it just does not get data from
a table or query. So it might seem inappropriate to use Access, but this is
intended to be a utility for Access. I was considering doing it outside of
Access, but then I realized some might say it should be done using Access.
You know, people will criticize just about anything.
I can turn this question around very easily: Why is
a bound, or un-bound form relevant to how you set, or get a value from a
control on a sub form?

I sure appreciate the ability to turn things around. I also try to think of
ways to reply sideways (seriously I do).
I don't think that a bound, or un-bound form really changes your
answer here...does it?

The question of bound or unbound is highly relevant since Requery can be
used with a bound control such as in the Northwind sample yet not with an
unbound control as in my situation.
So, in fact, I did ask for more clarification here, since there are in
fact
some issues that arise when using a un-bound form. And, even more issues
arise if you actually set the data souce of a form at rutnime. This would
mean that the form starts out un-bound..but becomes bound.

I might have chosen the wrong solution. So if there is a not a reasonable
solution to the solution I chose, then it is reasonable to say so. However I
will find another thread (such as start my own) rather than continue to
discuss the problem here.

Notice that I did ask a very, very, very specific question in my original
question. I asked how to set a textbox in the second subform from the first
subform, and I used the Northwind sample to provide specific controls and
context.
 
Back
Top