Solved Best Way to Grey Out a Button After Use (1 Viewer)

LGDGlen

Member
Local time
Today, 07:42
Joined
Jun 29, 2021
Messages
158
Hi all

I have a continuous form where the user can select a record and click a button to delete it as there are a number of processes i'd like to carry out when they delete the record.

After the delete process has ended i want the button go grey out until another record is selected.

I have 2 buttons on the form a "Delete" and "Delete-Grey" over the top of each other and when the record is selected the "Delete" button with the VBA attached is made visible and the "Delete-Grey" is hidden.

Once the VBA process ends I want to make the "Delete" hidden and the "Delete-Grey" visible but keep getting the error of the button can't have its visible status changed as it has focus.

So i try and set the focus to a different control on the form but it then errors with "can't move the focus to the control".

The weird thing is that as part of the process a second button is also made hidden and that bit works. Here is the VBA:

Code:
    Me.btnClearSelection.Visible = False
    Me.lstSupplier.SetFocus
    Me.btnDelConsignment.Visible = False
    Me.btnDelConsignmentGrey.Visible = True

So the first line (btnClearSelection.Visible) works, but then if i try and set the focus to the lstSupplier it fails with the can't move focus error, if i don't have the set focus step i get the "you can't hide a control that has the focus" as i'm trying to hide the button that the user clicked.

whats even weirder is if i step through after the error comes up it does work so i don't quite understand.

the form is a subform to a navigation form, so i thought it might have something to do with that, but that then doesn't explain the first line of code working and the others not.

just a bit confused

if there is a better way - i have read in places about transparent images but don't quite understand it - to do what i want to do to show/hide buttons depending on what the user is doing i'd appreciate direction

Kind regards

Glen
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:42
Joined
Feb 19, 2013
Messages
13,582
things to look at

is lstSupplier hidden or disabled?
What is the tab order (tab index property) for your controls? if the consignment button follows the clearselection button either change the order or change tab stop to no.
 

LGDGlen

Member
Local time
Today, 07:42
Joined
Jun 29, 2021
Messages
158
@CJ_London the lstSupplier is not hidden or disabled so i'll take a look at tab order/tab stop to no and see what happens thank you
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:42
Joined
Sep 21, 2011
Messages
9,319
Why not just change the Enabled property of the button?
 

LGDGlen

Member
Local time
Today, 07:42
Joined
Jun 29, 2021
Messages
158
@Gasman well thats certainly a way to do it and what i really should be doing instead of having grey buttons and hide/showing them as appropriate.............. tried that and it definitely works so i'm going to go through ALL my forms now and do that instead thank you
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:42
Joined
Feb 19, 2013
Messages
13,582
the lstSupplier is not hidden or disabled
In that case you should be able to set the focus to it.. You haven't said where your code is located - that might have an impact. One other thing to try is create an unbound textbox called say txtFocus and set height, width, top, and left properties to 0. Usually I would put it in the form header, but does depend how your form works, might need to go into the detail section

Also, be aware if this is a continuous form and the buttons are in the detail section, your code will change the button status on all rows.

To overcome this, use conditional formatting (it can disable as well). Unfortunately conditional formatting cannot be applied to buttons. The workaround is to use a textbox made to look like a button. Requires more code and you can't use the rounding/shading properties of a button
 

LGDGlen

Member
Local time
Today, 07:42
Joined
Jun 29, 2021
Messages
158
@CJ_London thank you for your input and help i have taken on board what you are saying........ but......... @Gasman 's answer works much better than what i was attempting to do by enabling/disabling the button instead of switching between 2 buttons one grey one not, means less controls on the form as well
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:42
Joined
Feb 19, 2013
Messages
13,582
Agree with disabling, much better user experience

But my comments were about where the buttons are - if they are in the header or footer, not a problem. The problem comes if they are in the detail section - you said it was a continuous form, disabling a control on one row will disable that control on all rows.
 

isladogs

CID VIP
Local time
Today, 07:42
Joined
Jan 14, 2017
Messages
15,569
Just in case you aren't already aware, you can't disable a button which has the focus. Move the focus to another object then disable the button
 

LGDGlen

Member
Local time
Today, 07:42
Joined
Jun 29, 2021
Messages
158
@CJ_London the buttons are in the header and footer not on the continuous part

@isladogs i'll keep it in mind, but in my testing everything has worked as expected and i've removed all the greyed out button controls and the processing is now alot simpler and much less VBA, but thank you it is appreciated and now i know i'll look out for any issues and move the focus as required
 

Users who are viewing this thread

Top Bottom