VB Code to Handle Dynamic Button Enabling

bballhermit

Registered User.
Local time
Today, 04:47
Joined
Oct 14, 2010
Messages
40
I have a form with a list box containing employee information. I have a button on the form that runs a command which deletes the currently selected employee. When no record is selected in the list box, I want the delete button to be disabled. To do this, I have the following function called in the form's "On Current" event. However, after running the delete command, and returning to the form from the msgbox that confirms the delete, no record is selected and the delete button is still enabled.

Is there a better way to do this? Or what am I doing wrong? Thanks.


Code:
'Update Enabled Delete Button Based on Employee Selected
Private Function UpdateEnableDelete()
    
    If IsNull(Forms!fmnuEmployees!lstEmployees) = False Then
        Me.cmdDelete.Enabled = True
    Else
        Me.cmdDelete.Enabled = False
    End If
    
End Function
 
I'd simply set the Default for cmdDelete.Enabled to False, then use the GotFocus and LostFocus events of lstEmployees to control the enabling/disabling of the button.

Linq ;0)>
 
Thanks, so when you say default are you referring to setting its property to disabled, or doing that in the code somehow? Thanks. I'm real new to Access.
 
Either way. You could do it programmatically in the Form_Load event, but the simplest way would be to select the button, in Design View, and go to the Properties Pane and disable it there.

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom