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 / Modules / DAO / VBA / January 2006

Tip: Looking for answers? Try searching our database.

Command Buttons

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CityGuy - 04 Jan 2006 18:49 GMT
I would like to disable a command button once it has been clicked,
via code attached to that button. Is this possible?

Any help with this is appreciated.  Thanks.
fredg - 04 Jan 2006 18:59 GMT
> I would like to disable a command button once it has been clicked,
> via code attached to that button. Is this possible?
>
> Any help with this is appreciated.  Thanks.

Code the command button Click event:

' First tell it to do what it is supposed to do.
' Then ...
[SomeOtherControl].SetFocus
Me!CommandButtonName.Enabled = False

Then how are you going to enable it again?
Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Kevin K. Sullivan - 04 Jan 2006 19:02 GMT
This is possible, but requires a little forethought.

- What control should receive the focus before the command button is
disabled?

- When should the button be re-enabled?  When a new record is selected?
 When a field value changes?  When the form re-opens?, etc.

The basic logic is:
'air code

Sub cmdButton_Click()

'run your code

'set the focus to another control
Me.OtherControl.SetFocus

'Disable this button
cmdButton.Enabled = False

End Sub

Many times, I'll Enable or Disable a button depending on value in a
field.  Therefore, I'll put something like this into the OnCurrent event
of the form:

'more air code
Sub Form_Current()

If Me!Status = "Processed" then
    'move the focus off of the button, if it has it
    if screen.activecontrol.name = "cmdButton" then
        me.othercontrol.setfocus
        me.cmdbutton.enabled = false
    end if
else
    me.cmdButton.enabled = true
end if

> I would like to disable a command button once it has been clicked,
> via code attached to that button. Is this possible?
>
> Any help with this is appreciated.  Thanks.
Klatuu - 04 Jan 2006 19:32 GMT
Glad I read this.  I was just trying to figure out where to put the code for
a button to disable it.  What fredg's answer does not address is that you
can't disable a control while it has the focus; however, this issue is, what
control do I set the focus to?  Since they will be record navigation buttons,
There is no way to quess where the user may go next.  My solution is to set
the focus to one of the other nav buttons.  For example, When I hit the first
record, I want to disable First and Previous, so, I guess I will set the
focus to the next button.

> This is possible, but requires a little forethought.
>
[quoted text clipped - 40 lines]
> >
> > Any help with this is appreciated.  Thanks.
 
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.