Disable command button

slharman1

Member
Local time
Yesterday, 23:55
Joined
Mar 8, 2021
Messages
483
Apparently you cannot disable a command button. Is it normal to write code to cancel the on click event if a forms control has data (is not null) or in the case of a date/time field > 0 ?
 
Hi. You should be able to disable a button as long as it doesn't have the focus.

Sent from phone...
 
you can have a Code in to the Form's Current Event to disable/enable the command button:
Code:
Private Sub Form_Current()
Me!ButtonX.Enabled = IsDate(Me!DateField)
End Sub

again on the DateField you set it on it's AfterUpdate Event:
Code:
Private Sub DateField_AfterUpdate(cancel As Integer)
Call Form_Current
End Sub
 
EnabledProperty.JPG
 
That is jogging a faint memory. You may have to make the button invisible rather than disabling it.

Although, I just tried it and the code didn't run when I disabled the command button. I used two separate buttons though so I didn't disable it using VBA. I just set the enabled property to false. Maybe when you set the property in code, there is a delay before it takes effect.

Please post your code
 
But when I disable it and then click the button, underlying code still runs.
man I doing something wrong?
Hmm, when a command button is disabled, it should turn gray (I think). Did yours do that? If not, maybe it isn't disabled. Also, you can verify if it's disabled or not by checking its Enabled property using code. Just a thought...
 
You can just set its Enabled property to False
If your command button is named MyCommand, then it's
Me.MyCommand.Enabled=False
You can also use the Visible property to hide or unhide the button.
 

Users who are viewing this thread

Back
Top Bottom