Matrix (1 Viewer)

janz

Registered User.
Local time
Today, 02:05
Joined
Jan 25, 2008
Messages
44
Hi,
I'm trying to fill a drawn matrix on a form.
There 50 fields I have to set (text and color) since the amount of fields can change I want to make a program to set the fields.
It's the same opperation all the time (just the field name is differnt)
This is what I'm trying

Dim a As Long
Dim jan As Object
Dim az As String

a = 0
az = "BackColor"
Set jan = Forms![matrix]![c0r0]

CallByName jan, az, VbLet, a

All what I need to know is how to change [c0r0] to C1r1 etc.
In otherwords get the object definition into a string.

However I can't find the way to do change that bl... string.:mad:
I tried almost all day with differnt methods like eval() etc etc
Who can help me
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 01:05
Joined
Jul 9, 2003
Messages
16,337
Handling multiple controls in MS Access and many programming languages is counter intuitive.

You have to think about the problem in a different way, and to help you do this I will give you a bit of background. Your Form is an object that can contain other objects, so your Form is also termed a “Container”, and the objects in the Form are called a "Collection" of objects.

You can access the properties of these objects on your Form, (the objects in the collection) by looping through the collection and making a change to each object in the collection individually, (but the same change to every object)

Imagine your keyboard represents the Form, and on this "keyboard form" there are keys, let's pretend the keys are actually text boxes with the name stamped on them --- A through Z so you have 26 named text boxes.

If you collected all these keys together and put them in a sack, you could reach in and pull out a key, however you would never know which key you were getting, if you wanted to find a particular key (let's say "W") you would have to keep picking them out one at a time until you found the "W" key. You would pick the key up to look at it thinking what key is this? And there embossed on the key would be the letter "W" identifying the key.

This is sort of how the collection works in MS Access, you have to look at each item (object) ask questions about it, (what are you) (what's your name) and then take action according to the answers you receive.

below is a typical example of the way you would do this:
Code:
Private Function fSetCap(strLblNumb As String, strLblCap As String)
'Name the labels
Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acLabel Then
            If Right(ctl.Name, 2) = strLblNumb Then ctl.Caption = strLblCap
        End If
    Next ctl
End Function      'fSetCap

read this line of code: "For Each ctl In Me.Controls"

Like this:
For each control in me controls

In other words for each item, (key) in me (the form) controls, (the collection of controls)

The next line "If ctl.ControlType = acLabel Then"
interrogates the selected control asks are you a label? If it's not a label it skips around the loop and checks the next control.

If it is a label, then the code checks the last two digits in the controls name to see if they match the variable past to the code via "strLblNumb" if it finds a control with a match, then it changes the controls caption to the passed in string variable "strLblCap".

I know this seems a long winded way about going about it, but not only does it work within MS Access it works in many other programming languages, and it's a very powerful way of working because you can change all of the controls in one go, you can select groups of controls by various methods, by the contents of the tag property, by coding the control name as in the above example, you can change practically anything about the control, it's back color, you can enable or disable it, make it visible or invisible all sorts of things.

More information HERE from beginner level right up to some advanced stuff I hardly understand myself!

.
.
.
.
.
 
Last edited:

janz

Registered User.
Local time
Today, 02:05
Joined
Jan 25, 2008
Messages
44
Uncle Gizmo, Your brilliant!! You saved my weekend!! It works like a charm. Thanks for the clear explination.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 01:05
Joined
Jul 9, 2003
Messages
16,337
Is that your website?

Yes, Well, I am slowly moving over to it, it is provided by www.ning.com and I find it very much easier to edit online than the old way --- editing my own site with MS Frontpage.

I'm not sure if it's the right thing to do, moving away from my own domain to one hosted by someone else, but I think this is the way things are heading, I am sure more and more things will be done on central computers, speech processing and the like. For example the videos on the site are hosted on http://www.viddler.com/TonyHine/, this is the only site where I've found you could view screen recording at a decent enough resolution to be clear. Again I could host these videos on my own web site, however by using Viddler I take advantage of their latest technology, and I get a bit more exposure!

Advantages
Ning and Viddler have the advantage of ease of use, access to the latest technology....

Disadvantages
You have to have Internet access to use it, to modify it, however if the Internet fails, your website's going to be useless anyway? So I don't know if this could be considered a disadvantage or not?
 

Users who are viewing this thread

Top Bottom