tags:

views:

621

answers:

3

I have an Access form displaying a tiny amount of data for a certain type of record. Basically it just prints the name on the left and on the right has a bunch of Rectangle controls whose background color I change in the form's OnLoad() function, according to results from a query performed using that record's ID as parameter.

This all worked fine, got my ID/name on the left and 31 boxes on the right, colored if that day of the month is reserved :) But needless to say that function can be completely arbitrary since it's code.

Then I decided to switch to 'continuous form' as to display as many records/items as possible. But alas, it was not to be -- all boxes were colored according to the query/function performed for the first record only. I figured that might be because it's the OnLoad() but changing it to OnCurrent() did not do much either. As it turns out, or that's what I read, the Rectangle intances are shared over the entire form and if I change the BackColor for one of them it changes for that box for each record.

I want to be able to change this according to a query performed on a per-record basis. Is there any way? Up until now I've only been able to find conditional formatting (the feature that's nor available for rectangles nor seems to cater my exact needs?) and kludgy Access 97 text-box hacks.

Thanks in advance :)

+1  A: 

You may be coming from an HTML background, where rectangles would be a natural solution. They aren't in Access. I don't think they'll work for you (in fact, "kludgy" could describe the attempt in my humble opinion).

You can however display an image. You'll keep an image for each status ready to call up. I've made visual displays this way. A little later I may be able to post some code, but I think you'll find this plays out pretty simply even if I don't.

ADDED NOTE: I'm glad this looks like it will work for you. You are concerned about "instanced only once" in your comment below. Yes, that's true for rectangles which are unbound controls (because they are designed for mere ornamentation). But you'll be using an image control which is a bound control (see Remou).

Smandoli
No. If you have 2 conditions (reserved=red, open=green), you use two images. Your sub-form uses an image control in place of the rectangle. You can name the images after whatever variable is already in use. I looked just now for my artifact. It's not here. But a help search on "image" will immediately instruct you (start with the help for Access, not VBA).
Smandoli
I'm a C/C++ lowlevel coder by heart/profession, actually :) What I (obviously) wanted is to quickly hack the following: 31 boxes in a row, display a color according to a codepath using record data. Not elegant, but supposed to do the job. The problem obviously is that the control properties are shared/instanced only once instead of per-record, which is what I expected. How do images resolve this? And do you by using images mean 31 different images for each permutation? Any case I'd prefer just having the GUI layer draw a vectorized shape rather than an image.. Please elaborate :)
nj
Sorry for "kludging" around with the comments - can never make my mind up :) Your solution sounds good.
nj
A: 

All unbound controls in a continuous form will be the same; bound controls can be varied using conditional formatting.

Remou
A: 

Change each rectangle to a text box, Control Source:

=Iif(myConditionIsMet,"ÛÛÛÛÛ","")

The "Û" is the Full Block character in Arial (asc 219).

maxhugen