Deselecting A Button (Help, Brain Cramp!)

CaliKidd

Board Regular
Joined
Feb 16, 2011
Messages
173
Hi all,

This should be easy for someone to answer. I'm just having a brain cramp today.

I am working on a simple Excel VBA app. It takes the user through a series of form that have Next and Back buttons to help them navigate.

So, let's suppose there are only two forms, called Form1 and Form2. When someone clicks on the Next button on Form1, I use the following code:

Code:
Private Sub Next_Button_Click()
[INDENT]Form1.Hide
Form2.Show
[/INDENT]End Sub

I am hiding the form (not unloading it) because I want to allow the user to back up to the first form if he needs to by clicking on the Back button, as follows:

Code:
Private Sub Back_Button_Click()
[INDENT]Form2.Hide
Form1.Show
[/INDENT]End Sub

Here's the problem:
When backing up to Form1, the Next button is depressed since it is still in the "clicked" state. How can I get the button back to the raised "unclicked" state?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
When I do that the Next button has focus, but is not depressed. If you have another control that should have the focus when the form is activated, then you can use control.SetFocus to make it take focus. I believe that some control on a from always has to have focus.
You can also set the buttons .TakeFocus******* property to false.

That should read T a k e F o c u s O n C l i c k, but part of it changed to asterisks ???
 
Last edited:
Upvote 0
Hi Phil,

Thanks for the reply. Well, I don't think the problem I am experiencing is a setfocus issue. I can change the focus to a different object and the Next button which was initially clicked is still in a "toggled" state.

Also, the TakeFocus O n C l i c k property you mentioned is not available to the command button I'm using. I should have been more specific. I am using Excel 2007 and the command buttons from the standard VBA toolbox (i.e., Microsoft Forms 2.0 Command Button).

What control are you using to set the TakeFocus O n C l i c k property? As an aside, if I install an additional control from the list of available controls, use it in my VBA app, and then send the app to someone on a different PC, will it work for them "out of the box" or will they be prompted to "find" that object or do some sort of manually config before it will work? I've not added any extra controls to my PC, so I'm assuming that the long list of unselected controls available to me come with Excel 2007 and therefore should be available to other users too, but can you confirm or clarify this for me? I've never tried it before.
 
Upvote 0
CaliKidd

There is a TakeFocusOn... property for command buttons from Forms 2.0, it's been there for quite some time I think.

By the way, why are you just hiding the form?

Is there data on it that needs to be preserved if the user wishes to return to it?

Have you considered doing everything on one form?

Perhaps a multitab with a page for each of the existing forms.

Or even something where the first part of the form appears in the top half and when continue is clicked the form expands to display the next part.
 
Upvote 0
Norie, OMG, I'm so embarrassed... I was using a Toggle Button, not a Command Button! That's why I couldn't find the TakeFocus property. I guess that brain cramp was more of a programming seizure. :eeek:

To answer your other questions, I can't fit everything on one form, expanded or not. I could use a multitab form, but I've opted to use multiple forms instead because I want to create the look and feel of a setup routine that walks you through it step by step. I suppose I could pull this off with a multitab form but I'm not sure it would be any easier since I would have to disable the other tabs or make them invisible so the user wouldn't click things out of sequence.

As for why I am hiding the forms, it's basically due to the fact that selections are made/saved on each form and I want to give the user to back up and change those selections, if needed. Hence, I didn't want to unload the forms from memory until the "set up" process was finished.

If you have a better approach, please let me know.

Also, I would still like to hear back from you or anyone else about the last "aside" question I raised earlier.
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top