Hidden/locked command button (1 Viewer)

Pete490h

Member
Local time
Today, 18:44
Joined
Jan 18, 2021
Messages
44
I have a command button on an entry form that only has to be pressed once
To ensure this, is there a setting and/or code that can either hide or lock the button after it’s one off pressing
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:44
Joined
Oct 29, 2018
Messages
21,467
What does it do when you press the button?
 

GPGeorge

Grover Park George
Local time
Today, 10:44
Joined
Nov 25, 2004
Messages
1,850
I have a command button on an entry form that only has to be pressed once
To ensure this, is there a setting and/or code that can either hide or lock the button after it’s one off pressing
Once ever, in the lifetime of the application? Or once during a given session? Or once for a specific record currently in the form?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:44
Joined
Feb 28, 2001
Messages
27,172
OK, to answer the mechanical part of the question, it is possible to disable a command button but you can't lock it. You can also make it transparent (i.e. not visible.) Note, however, that you cannot do this from the command button's click event because you can't disable the control that currently has focus, and after a click, the button WILL have focus.

If you disable the button, then nobody can click it. You can also make it transparent, which means nobody can even see it. You would probably want to set cmd.Enable=False and, optionally, cmd.Transparent=True for the button-control (here, named cmd, but you can put in the correct control name.)

The catch is WHEN to do it as well as how / when to undo it. When you click the button, there is a click event and that is where most of the work of the button gets done. HOWEVER, as long as the command button retains focus, it cannot be disabled. So that means you need some way of knowing that the button needs to be / stay disabled. GPGeorge's question becomes immediately relevant. There are some tricks one can play, but generally the best way is a software flag in the form's class module's declaration area that remembers that the button was disabled. That way, you can test in the button-click routine whether the button IS supposed to be disabled and, if so, just do an Exit Sub without doing anything else. BUT this might not be enough, depending on the intended persistence of the button's condition.

I can tell you the method and some tricks of the trade, but without knowing the strategy of the question, nobody is going to give you a really good answer. We don't know the "rules" of this exercise.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:44
Joined
May 21, 2018
Messages
8,527
I do not think you answered @GPGeorge question, because the code would be vastly different.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:44
Joined
Feb 28, 2001
Messages
27,172
You still haven't told us the persistence of the implied condition. How long is this "disabled" condition supposed to last? When, if ever, can the command button be enabled again, and WHY (under what conditions) would you enable it?

Is it record-related? Session-related? Date-related? Suppose you fire the button, do your thing with the supplemental data form and close it, then go on about your other business. You shut down session 'cause it's quitting time. You come back tomorrow and launch the Access DB. What should be the state of that button and why? This is what I meant by the strategy of the button.
 

Pete490h

Member
Local time
Today, 18:44
Joined
Jan 18, 2021
Messages
44
OK, to answer the mechanical part of the question, it is possible to disable a command button but you can't lock it. You can also make it transparent (i.e. not visible.) Note, however, that you cannot do this from the command button's click event because you can't disable the control that currently has focus, and after a click, the button WILL have focus.

If you disable the button, then nobody can click it. You can also make it transparent, which means nobody can even see it. You would probably want to set cmd.Enable=False and, optionally, cmd.Transparent=True for the button-control (here, named cmd, but you can put in the correct control name.)

The catch is WHEN to do it as well as how / when to undo it. When you click the button, there is a click event and that is where most of the work of the button gets done. HOWEVER, as long as the command button retains focus, it cannot be disabled. So that means you need some way of knowing that the button needs to be / stay disabled. GPGeorge's question becomes immediately relevant. There are some tricks one can play, but generally the best way is a software flag in the form's class module's declaration area that remembers that the button was disabled. That way, you can test in the button-click routine whether the button IS supposed to be disabled and, if so, just do an Exit Sub without doing anything else. BUT this might not be enough, depending on the intended persistence of the button's condition.

I can tell you the method and some tricks of the trade, but without knowing the strategy of the question, nobody is going to give you a really good answer. We don't know the "rules" of this exercise.
Okay, I’ll try to explain…..
This main form opens when selected from another project form and becomes a unique record and is given an Inspection Report No
The user fills required data in the green cells
There are three subforms and relevant data is entered on the Feature Information subform
The user then clicks the GenerateComp button (THIS IS THE BUTTON IN MY INITIAL QUERY)which is under the Component Result subform
Please ignore the 1 of 21530 records currently shown
You will notice on the main form a cell named Component Qty, which will have the relevant number
When the GenerateComp button is clicked, a procedure runs that copies the Feature Information as many times as the Component Qty
This then provides a unique Inspection Report No/Component Qty/Feature Information

This form works really well but I just want to ensure the GenerateComp button is only pressed once

Hope this suitably explains😉
 

Attachments

  • 869389D2-1B17-44CC-832C-9524148B8EC8.jpeg
    869389D2-1B17-44CC-832C-9524148B8EC8.jpeg
    229.2 KB · Views: 155

Gasman

Enthusiastic Amateur
Local time
Today, 18:44
Joined
Sep 21, 2011
Messages
14,264
So the result of pressing the button is something is generated?

So, test to see if that something is generated and hide/disbale the button if so?

Possibly a DCount() > 0
 
Last edited:

Pete490h

Member
Local time
Today, 18:44
Joined
Jan 18, 2021
Messages
44
You still haven't told us the persistence of the implied condition. How long is this "disabled" condition supposed to last? When, if ever, can the command button be enabled again, and WHY (under what conditions) would you enable it?

Is it record-related? Session-related? Date-related? Suppose you fire the button, do your thing with the supplemental data form and close it, then go on about your other business. You shut down session 'cause it's quitting time. You come back tomorrow and launch the Access DB. What should be the state of that button and why? This is what I meant by the strategy of the button.
Sorry, learning how to answer replies correctly, as sometimes miss info you guys need…..

I’d like the button to be disabled (hidden sounds best), after it’s been pressed once for that inspection report number, even when the same record is reopened
When a new Inspection Report No is created, the button needs to automatically re-appear for the new report etc
Hopefully I’ve added ‘more flesh to the bone’ and it’s enough…..
 

isladogs

MVP / VIP
Local time
Today, 18:44
Joined
Jan 14, 2017
Messages
18,213
In the on click event, first set the focus to another control then you can hide/lock your button.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:44
Joined
Oct 29, 2018
Messages
21,467
It opens another form in the background and fills some data, then closes the background form
Don’t want to duplicate this data
Hi. Thanks for answering my question, and my response would be the same as @Gasman's. After the other form data is created, you can now check if it exist. For example, you can use the Form's Current Event to check for that data. If it exists, you can hide the button.

Or, in the click event of the button, you can check if the data exists. If so, use a MsgBox to inform the user or just ignore the Click. Otherwise, open the other form as usual.

Hope that helps...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:44
Joined
Feb 19, 2002
Messages
43,257
If you want the button to be invisible when the form opens if it has been "pushed" previously, you are going to have to tell us HOW TO IDENTIFY based on DATA in some table that the button has already been pushed. If there is NO data footprint you can identify, then there is no way to do what you want.
 

Users who are viewing this thread

Top Bottom