Sure Rick,
It's the same old story. I want to create a certain amount of
rectangles based on the amount of records in a table (which can vary)
and update the subform for any new or deleted records (also some other
info if the record has been changed, but not deleted).
But, unlike what everybody thinks, which is some kind of continuous
form of controls based on the records, I want to create a kind of
"Matrix", a nxn grid of rectangles.
So, the user has an interface, say the Main form, to
browse/update/delete the records (in a subform datasheet) and then
click a button that will generate the grid.
The grid will be on a form and shown in a subform control after
created.
Now, once the grid is generated, each rectangle should have the click
event code to respond to the user, who will click each rectangle as
needed and change the color of the rectangle clicked. There are
multiple colors which each mean something different.
When the user clicks a rectangle, a cooresponding record in the table
is updated.
If the user deletes or adds a record, a row of rectangles is added or
removed.
Mathematically (if I have this right) it is a "Cartesian Cross Product"
of the records in
a table with itself. Kind of like how a multiplication or addition
table looks.
The record id is at top and across, labeling each column in the grid,
and at the left
and down, labeling each row in the grid. The user marks the color of
each grid based
on the condition or meaning of combination of a row and column id
value.
Naturally, like squares in a multiplication table, the diagonal
rectangles would represent the pair (id,id).
So given a table with n records, create an nxn grid, labeling the top
and left with the record id, and allowing the user to click a rectangle
to change its color, update the table with the color value chosen after
the click event.
Now, one could, theoretically, upon creating the grid, calculate the
cross product pairs and populate another table, and with that other
table somehow generate each rectangle, of course with the same click
event features as above.
Hope this helps and thanks for responding,
Christopher
> I'd say that on a subform, if your rectangle is in the detail section, and
> if your subform is in continuous or datasheet view, then your rectangle will
[quoted text clipped - 5 lines]
> and its events. Can you say more about why you need to do this? You might
> not have to take this approach.
Rick Wannall - 02 Jun 2006 19:59 GMT
If there's any way of knowing ahead of time the maximum number of
rectangles, you might be better off creating all of them ahead of time in
design view. Then hide or reveal them based on your data.
Access is pretty object oriented, but it's not enough so, I think, for you
to be able to create your subform as an object and then create controls as
objects and add them to the collection as you could in flavors of C or VB
these days.
If having them all, and hiding or revealing, is good enough, you would be
able to load up the tag property of each rectangle with values needed to
accomplish the task related to that rectangle. As you click even, use
"=MyClickEvent()".
IN your module (subform, down where the rectangles are) you need a public
function named MyClickEvent. It would refer to Screen.ActiveControl to get
to the clicked rectangle. E.G.:
dim c as control
set c = screen.activecontrol
c.backcolor = vbwhite
if c.tag = "You Win" then
msgbox "Hot dog!"
else
msgbox "Try again"
endif
Would that help you?
By the way, if you're not showing multiple records, why put this in a
subform? There are plenty of other reasons, but if it's okay I'd like to
ask yours.
cefrancke@yahoo.com - 02 Jun 2006 20:24 GMT
Thanks Rick,
I was using a subform in order to open it hidden in design mode, create
all the rectangles, save, then show the subform in a subform control on
the Main form. Another subform on the Main form will have the records
to create the rectangles by.
Hope this helps,
Christopher
> If there's any way of knowing ahead of time the maximum number of
> rectangles, you might be better off creating all of them ahead of time in
[quoted text clipped - 28 lines]
> subform? There are plenty of other reasons, but if it's okay I'd like to
> ask yours.
cefrancke@yahoo.com - 02 Jun 2006 21:19 GMT
Rick,
Is there another way to get the id of the rectangle clicked in the
subform?
Apparently there is no focus for rectangle so Screen.ActiveControl is
not working.
I may have to hard code names or use mouse coordinates, any ideas?
Thanks
> Thanks Rick,
>
[quoted text clipped - 39 lines]
> > subform? There are plenty of other reasons, but if it's okay I'd like to
> > ask yours.
Rick Wannall - 02 Jun 2006 21:37 GMT
Of course you're right. I forgot about rectangles. Can you use textboxes
with appropriate back and fore colors instead? Text boxes can receive
focus, whereas rectangles, naturally, cannot.
Sorry about that.
Text boxes should fix you up.