how do you reference individual controls for selected record on a form?

S

SWu

Hi everyone

I've created a form with a detail section that displays all records from a
table. In code, when I reference a control and its properties in the
details section (e.g. Address1.ForeColor), it affects ALL Address1
textboxes. If I change the forecolor for Address1, all 10 or 20 or however
many records there are, get affected. How do you refer to Address1 for any
particular record?

Also, is there an event that fires repeatedly when the form shows all
records?

Please don't tell me to use Conditional Formatting as that doesn't apply to
all controls plus doesn't give me enough flexibility for what I want to do.

This should be pretty simple for someone used to coding Access VBA (I'm new
to it but old at VB in general!). Any help at all that gets me looking in
the right direction would be greatly appreciated.

TIA,
Stephen
 
A

Albert D. Kallal

Re: how do you reference individual controls for selected record on a
form?

Well, you can't since they are not individual controls. A continues form
simply repeats the data, but does NOT repeat (clone) the controls.

This approach is MUCH different then using a data repeater control in VB, or
even using the clone method, and a control array in vb (both of which
requite a lot of code..but make separate instances for each record (and the
associated extra overhead of such an approach).

Of course, the advantage of the access setup is that you can fully design a
detail line as a grid, and it repeats the data for you (I have wished for
this ability in VB for years). There is some nice screen shots of using
continues forms in ms-access here (this shots might give you some ideas).

http://www.attcanada.net/~kallal.msn/Articles/Grid.htm
Please don't tell me to use Conditional Formatting as that doesn't apply to
all controls plus doesn't give me enough flexibility for what I want to
do.

The above is one of your choices. If conditional formatting can't be used in
your special case, then your choices for using a sub-form are limited.

There is some sample code here to highlight stuff:

http://www.lebans.com/formatbycriteria.htm

There is also a few kluge examples that can be used in the following link
(but, I don't like them, and they are for versions of access that did NOT
have conditional formatting (access97 and earlier). However, you might just
take a look at them, those examples can be found here:

http://www.mvps.org/access/resources/downloads.htm


You can also consider using a 3rd party grid. (perhaps your favorite grid in
VB comes to mind here?)

So, last but not least...I suppose you could use your favorite VB control
(since you mention that this is a snap. Most, if not all VB grid controls do
work in ms-access (in fact, most activeX controls do work). So, if your
super easy snappy and simple to use VB solution exists....then why not use
that solution to solve this problem and be done with it? (you will not be
using a sub-form..but your VB solution should work here).
 
S

SWu

Albert,

Thank you very much for your detailed reply. I'm somewhat incredulous that
it isn't possible to say "for record no. 33, I want my CommandButton hidden"
or to code against an event that fires each time so that you can say "for
the record that this event is firing against, don't show my CommandButton if
Address1 is empty".

To use your URL as an example (this one in particular,
http://www.attcanada.net/~kallal.msn/Articles/gs3.gif) are you saying that
it isn't possible to make only SOME of the glasses appear depending on
values in, say, the From field (assuming that Conditional Formatting doesn't
apply)?

Thanks again,
Stephen
 
A

Albert D. Kallal

SWu said:
Albert,

Thank you very much for your detailed reply.

You are welcome. I kind of wish I had a better answer for you...but I don't,
and it is not the way access works.
To use your URL as an example (this one in particular,
http://www.attcanada.net/~kallal.msn/Articles/gs3.gif) are you saying that
it isn't possible to make only SOME of the glasses appear depending on
values in, say, the From field (assuming that Conditional Formatting doesn't
apply)?

No, you can't . On the other hand, to create that button, I just drew ONE
button on the form. Nothing else special needed to be done to repeat that
button. Further, the code behind the button to launch the form is only ONE
LINE of code. That ONE line of code will open the form, and load it to the
one line of detail that I clicked on (this again, is rather remarkable that
you can do this with one line of code).

(for info sake..that one line is:)

docmd.OpenForm "frmIDetails",,,"id = " & me.id

I also used the commercial t-list grid control in ms-access. Here is a
sample screen of this..and you can see that it was run in ms-access:

http://www.attcanada.net/~kallal.msn/test/tlist.htm

The above also has a link to their site.

However, that control does take code to load it up (just like most VB grids
do. You don't get spoiled like you do in ms-access, where it does all the
work..but then again you do gain in flexibility.
 
S

SWu

thanks. at least your answer was educational and saved me from any further
frustration!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top