How do you disable (or hide) a command button when a list box contains no data in it? I tried the Enabled = False and Visible = False parameters in my VBA code, but it either does it when I don't want it to, or doesn't do it at all.
Could you give us more detail? Where do you have the code that you tried to use stored? Can you post the code you are trying? what are the names of the listbox and the command button? Kathryn
I am trying to link code to the following command buttons: cmdFirst, cmdPrevious, cmdNext, and cmdLast.
These command buttons will check to see if there is any data in a list box (lstEnvChecks).
If there is no data in that list box, I want to disable two command buttons: cmdChangeRecordEnvChecks and cmdRemoveRecordEnvChecks; otherwise I want those two command buttons left enabled.
Here is the code that I was trying to use:
If IsNull(Forms!frmInmateMaster!lstEnvChecks) Then
Forms!frmInmateMaster!cmdChangeRecordEnvChecks.Enabled = False
Forms!frmInmateMaster!cmdRemoveRecordEnvChecks.Enabled = False
Else
Forms!frmInmateMaster!cmdChangeRecordEnvChecks.Enabled = True
Forms!frmInmateMaster!cmdRemoveRecordEnvChecks.Enabled = True
End If
I also tried the above-mentioned code using "Visible" instead of "Enabled", to no avail.
OK, first of all, I think I would put the code to check if there is any data in lstEnvChecks in the Form's OnCurrent event. That event fires every time the focus moves to a record, making it the current record, or when the form is refreshed or requeried.
To make your code more readable, assuming that all of this is occuring on Forms!frmInmateMaster, you can replace Forms!frmInmateMaster with Me in your code above. The Me keyword is very handy that way.
If IsNull(Me!lstEnvChecks) Then
Me!cmdChangeRecordEnvChecks.Enabled = False
Me!cmdRemoveRecordEnvChecks.Enabled = False
Else
Me!cmdChangeRecordEnvChecks.Enabled = True
Me!cmdRemoveRecordEnvChecks.Enabled = True
End If
I would probably put a breakpoint on the first line above and then run your form. When the code pauses, use the F8 key to step throught the code and see what all the values are.
If you need more detailed explanation, let me know.
Kathryn
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.