Grouping Items in Access

fantimm

Registered User.
Local time
Today, 15:24
Joined
Jul 27, 2007
Messages
11
Hey guys, got a question about a form I am working on.

Basically, on my form, the entire bottom half is only relevant for some records. So at the top I have a check box the user can click to say whether they only need the basic text boxes up the top to enter data, or whether they also need the other fields. So basically I have a check box, and when it is ticked I want a whole bunch of text boxes, labels etc, to appear. And then when the box is unchecked, they should disappear again. Pretty Simple.

I am doing it with macros and have already done lots of other visibility controls in my database with them. What I am wondering is, is there a way to group all those items at the bottom of my form and give them a name so I can just tell it to set [groupName].Visible to Yes/No. I really don't want to make some huge macro with the condition of checkbox=true repeated a hundred times, manually setting all the items visibility to true etc.=

The only grouping I have found seems to be for formatting purposes only, where you group items together and then you can move them as one, like grouping drawn shapes in microsoft word - there doesn't seem to be any name you can reference to be able to control the properties of the group in a macro or anything.

So is there a simple way I can just select items on my form, give them a group name, and then just go [groupName].Visible = Yes ?
 
I don't think that a grouping feature as you desire it is available (although I do understand that it is possible to iterate through all of the controls on a form, I would not know where to start on seperating out the ones you don't need).

In VBA you could create a subroutine procedure ('sub') that switches the visibility of the controls on and off. Something along the lines of:
Code:
Private Sub switchOnOff (blSw as Boolean)

    me.controlName1.visible = blSw
    me.controlName2.visible = blSw
    'include all controls as required'

End Sub

You then call this procedure:
Code:
 Call switchOnOff(true)

to make the controls visible, substituting 'false' for 'true' to hide them.

You can then call the same routine from different places without having to repeat all the typing, and also have the ability to choose whether to hide or show the controls...

HTH

Tim
 
Hmm OK. I'll give that a try, although I prefer to stick to macros...
When entering a macro, and I have Action: SetValue, it has Item and Expression. Can I tell it to set multiple items in the one line? like this:

Item: [field1].[visible] AND [field2].[visible]
Expression: Yes

I tried using the and operator but it threw an error at me.
 
Macros are (apparently, as I mostly skipped them) very good for doing simple tasks easily. However, for better/more control then the way ahead is VBA. Access had a nifty little feature build in that will actually convert a macro to VBA, so you could use your original macro as a building block and see what code Access would make of it (if you were that way inclined).

Although I haven't had much experience with Macros I'd hazard a guess that you can't achieve what you want to. That said, (and I'm sure that you'll realise that I am guessing here) have you tried separating the item list with commas or semi-colons rather than AND? My other guess is that if 'item' is an expression it should evaluate to a single value, so setting multiple items won't be possible.

Perhaps, as this is a very specific question related to a macro, you would be better off posting it in the Macro forum, where the people with more knowledge of macros reside/visit. If for no other reason than, for the benefit of others who might one day search the forum for the same information.

VBA really is the way ahead if you're going to continue to produce databases and don't want to be bound to only using Macros, which are not as powerful as VBA. Discard your shackles and embark on the VBA route, you just know that you're going to have to one day, why not make it today? :)

Tim
 
Yeah I have done it now. Ended up just setting each of the elements in the macro manually. It took a bit longer than I would have liked, and is probably a lot less efficient, but oh well.

Yeah I probably should learn VB, but I am still resisting. I am just so used to C++ I guess, that coding in anything else just seems weird.
 

Users who are viewing this thread

Back
Top Bottom