Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / February 2008

Tip: Looking for answers? Try searching our database.

diable command button based on field value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
barrynichols@gmail.com - 04 Feb 2008 16:20 GMT
I have a command button which I would like to disable based on the
following rules:

If A = 1 then button is disabled
If B = 2 then button is enabled
Klatuu - 04 Feb 2008 16:50 GMT
Where you put the code depends on how the form works.  If this needs to be
checked for each record, use the form current event:

   If A = 1 Then
       Me.Button.Enabled = False
   ElseIf B = 2 Then
        Me.Button.Enabled = True
   End If

But, what if A is not 1 and B is not 2?

Signature

Dave Hargis, Microsoft Access MVP

> I have a command button which I would like to disable based on the
> following rules:
>
> If A = 1 then button is disabled
> If B = 2 then button is enabled
barrynichols@gmail.com - 05 Feb 2008 08:46 GMT
> Where you put the code depends on how the form works.  If this needs to be
> checked for each record, use the form current event:
[quoted text clipped - 18 lines]
>
> - Show quoted text -

Dave,

Thanks for this.

It should have read

If A=1 then..
A=2 then....

Sorry for the confusion.

I've got the code working, however, is there a way to get it to work
"live", i.e. without having to change records and then go back to the
one I was working on for the button to change? Saving the current
record doesn't seem to help.

Thanks
Klatuu - 05 Feb 2008 14:21 GMT
If you put the code in the Form Current event, it should take care of
resetting the button for each record.  If that is not what you are trying to
do, then I don't understand the question.
Signature

Dave Hargis, Microsoft Access MVP

> > Where you put the code depends on how the form works.  If this needs to be
> > checked for each record, use the form current event:
[quoted text clipped - 36 lines]
>
> Thanks
barrynichols@gmail.com - 05 Feb 2008 15:48 GMT
> If you put the code in the Form Current event, it should take care of
> resetting the button for each record.  If that is not what you are trying to
[quoted text clipped - 45 lines]
>
> - Show quoted text -

It does reset the button for each record, however the change to the
button is not instant.

So the default setting for the field is A=1 thus button is disabled.

When I change to A=2, the button is not enabled until I go to another
record and then return to the same record. (i.e. save and refresh)
Linq Adams - 05 Feb 2008 16:11 GMT
You need your code in the AfterUpdate event of your textbox A for the change
to take place immediately. You still need it, of course, in the Form_Current
event to persist this when returning to records.

Signature

There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Klatuu - 05 Feb 2008 16:48 GMT
Linq is correct.  I would suggest you put the code in a sub in your form
module and call it from the After Update event of A and from the Form Current
event.  That way you only have one place to make changes.
Signature

Dave Hargis, Microsoft Access MVP

> > If you put the code in the Form Current event, it should take care of
> > resetting the button for each record.  If that is not what you are trying to
[quoted text clipped - 53 lines]
> When I change to A=2, the button is not enabled until I go to another
> record and then return to the same record. (i.e. save and refresh)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.