A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Disable and Enable command button



 
 
Thread Tools Display Modes
  #1  
Old December 20th, 2006, 06:10 PM posted to microsoft.public.access.forms
mdavis via AccessMonster.com
external usenet poster
 
Posts: 15
Default Disable and Enable command button

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.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1

  #2  
Old December 20th, 2006, 06:33 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Disable and Enable command button

Not knowing how your form works, I can't say exactly where you need to put
the code, but this is basically it:

Me.cmdADD.Enabled = Me.MyListBox.ListCount = 0
Me.cmdEDIT.Enabled = Not Me.MyListBox.ListCount = 0

"mdavis via AccessMonster.com" wrote:

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.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1


  #3  
Old December 20th, 2006, 09:47 PM posted to microsoft.public.access.forms
NthDegree via AccessMonster.com
external usenet poster
 
Posts: 14
Default Disable and Enable command button

Would this do it for you?

Run this code from the "After Update" action of the list box.

if isnull(listbox) or listbox = "" then
cmdAdd.Enabled = True
cmdEdit.Enabled = False
else
cmdAdd.Enabled = False
cmdEdit.Enabled = True
end if

As a suggestion, I would put both command buttons on top of each other and
then in the code above substitute "Visible" for "Enabled". The way they would
only see the button that is appropriate for the situation.

mdavis wrote:
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.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1

  #4  
Old December 20th, 2006, 11:56 PM posted to microsoft.public.access.forms
mdavis via AccessMonster.com
external usenet poster
 
Posts: 15
Default Disable and Enable command button

Thank you for the quick response. It is almost working.

I forgot to mention that the ADD and EDIT command buttons open up a pop up
form to either "add" or "edit/delete" a record. Where would I put code to
move the focus from either command buttons on Form A (the main form) after I
have closed the pop up forms?

Both of the pop up forms have a SAVE and CANCEL command button.

Thanks for your help. Cool idea about stacking the command buttons on top of
each other.

NthDegree wrote:
Would this do it for you?

Run this code from the "After Update" action of the list box.

if isnull(listbox) or listbox = "" then
cmdAdd.Enabled = True
cmdEdit.Enabled = False
else
cmdAdd.Enabled = False
cmdEdit.Enabled = True
end if

As a suggestion, I would put both command buttons on top of each other and
then in the code above substitute "Visible" for "Enabled". The way they would
only see the button that is appropriate for the situation.

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.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:27 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.