Disable/Enable Command Button

  • Thread starter Thread starter mdavis via AccessMonster.com
  • Start date Start date
M

mdavis via AccessMonster.com

Form A has an unbound list box based on a query. When the list box has a
record in it I want a command button called ADD to be disabled and a command
button called EDIT to be enabled.

When their isn't a record in the list box I would like the ADD command button
to be enabled and the EDIT command button to be disabled.

Also know that the ADD and EDIT command buttons open up pop forms that will
allow the user to either add or edit records.

When Form A is closed and reopened I would like the ADD and EDIT command
buttons to be enabled or disabled based on the value of the list box.

Thank you in advance.
 
mdavis said:
Form A has an unbound list box based on a query. When the list box
has a record in it I want a command button called ADD to be disabled
and a command button called EDIT to be enabled.

When their isn't a record in the list box I would like the ADD
command button to be enabled and the EDIT command button to be
disabled.

Also know that the ADD and EDIT command buttons open up pop forms
that will allow the user to either add or edit records.

When Form A is closed and reopened I would like the ADD and EDIT
command buttons to be enabled or disabled based on the value of the
list box.

Thank you in advance.

Might I suggest a single button with a caption of Add/Edit and a single form
that does both functions? All you have to do is filter on the entry in the
ListBox when opening a single form to accomplish both adding and editing.
 
Could you give me an example of the code I would use to accomplish this?

Rick said:
Form A has an unbound list box based on a query. When the list box
has a record in it I want a command button called ADD to be disabled
[quoted text clipped - 12 lines]
Thank you in advance.

Might I suggest a single button with a caption of Add/Edit and a single form
that does both functions? All you have to do is filter on the entry in the
ListBox when opening a single form to accomplish both adding and editing.
 
mdavis said:
Could you give me an example of the code I would use to accomplish
this?

Use the command button wizard in design view of the form with the ListBox. The
wizard options would be...

Form Operations - Open Form
Name Of the Add/Edit form
Open The form and find specific data to display
ListBoxName - FieldName

That will construct code for the button that uses the DoCmd.OpenForm method with
a supplied WHERE aregument that will pre-filter the form being opened to match
the value currently selected in the ListBox. When no matching record exists
(like when the ListBox is empty) then the form will be opened to the blank
NewRecord position ready to add a new record.
 
Back
Top