View Full Version : on click for cmds


pascaly
11-09-2008, 03:19 PM
Hi,

code noobie, so would love some help here.

I have a form with several controls (mostly txt and chk). When I click a cmd, I have set some of the controls to Visible = False and some to Visible = True depending on what the user needs to see at the time.

What I'd like to do, is if the user clicks this same cmd again, the form reverts back to the previous view, and they can switch between the two views of the form as many times as they like.

I think the code goes on the On Click event, just not sure what I need! Any help greatly appreciated.

If I'm not clear, please let me know, thanks.

pbaldy
11-09-2008, 04:40 PM
One option would be a toggle button instead of a normal button. You test the value of the button and set your values appropriately. I think there's sample code in VBA help.

marleymanner1
11-09-2008, 06:29 PM
I do this quite often...and what I do is extremely manual. Here is an example of what I do if you want to use it:me.control1.visible = false
me.control2.visible = false
me.control3.visible = false

me.control4.visible = true
me.control5.visible = true
me.control6.visible = true

me.cmdbutton.caption = "Switch to View #2"

DCrake
11-10-2008, 03:13 AM
When you click on the command button use the code

Me.ControlName.Visible = Not Me.ControlName.Visible

pbaldy
11-10-2008, 10:36 AM
Funny, I'm usually the one who posts the one-line boolean logic solution. It slipped my mind this time. Good catch.

pascaly
11-10-2008, 01:55 PM
Great, thanks everyone, I haven't tried it yet, but thanks for your help.