Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command buttons 1

Status
Not open for further replies.

kpryan

Technical User
Aug 24, 2005
282
0
0
US
Hi all,

I have a form with a command button which updates an append query.
What I want to do is that once it has been activated is to lock the button. When the form is reopened it will unlock the command button. Is this possible in MS ACCESS?
 
make sure your in your properties for the button that enable = true.

Then in the onClick event for your button you do this

docmd.setwarning false 'I do this so that it won't remind me I am about to append records
docmd.openquery "YourQueryName"
button1.enable = false 'this will disable your button.
docmd.setwarnings true 'turn warnings back on
That should work. If you want to be safe, you can add this in the onOpen event for your form

if button1.enabled = false then
button1.enable = true
end if
 
Thanks jimati,for geeting back to me.
have used the code, but get an error when the command button is clicked.."You can't disable a control while it has the focus. Not sure what this means.
Can you help further.

many thanks,

Ken
 
Ken

When you click on the button, you make it the active control on the form. This is called giving the focus to the control. While any control has the focus, it can not be disabled.

You need to move the focus away from the button and then disable it.

Code:
docmd.setwarning false 'I do this so that it won't remind me I am about to append records
docmd.openquery "YourQueryName"
[b]Another_Control.SetFocus[/b]
button1.enable = False 'this will disable your button.
docmd.setwarnings true 'turn warnings back on

You can set the focus to any other visible control on the form. I usually set it to the next control that the user will need to action.

HTH
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top