Disable command button

slharman1

Member
Local time
Today, 14:14
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
 
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