How do I make my button disabled!

Sohaila Taravati

Registered User.
Local time
Today, 23:17
Joined
Oct 24, 2001
Messages
266
I have a button called Approved on my form. when the user presses it would put a check mark in a field. I want my button to be disabled when they click the button. This is my code:

Private Sub ButtonApproved_Click()
Approved = -1 'Sets field to yes
ATimestamp.Locked = False 'Allow edits
ATimestamp = Date 'Set time
ATimestamp.Locked = True 'Lock feild again
If (Me.Approved = -1) Then
Me.ButtonApproved.Enabled = True
Else
Me.ButtonApproved.Enabled = False
End If
End Sub

But it dosen't work. What am I doing wrong?
Thank for your help in advance.
smile.gif
 
Try setting the focus to another control before you disable the button.

Additionally you will need to put similar code in the OnCurrent event to toggle the switch when you change records.

try:

Approved = -1 'Sets field to yes
ATimestamp.Locked = False 'Allow edits
ATimestamp = Date 'Set time
Me.ButtonApproved.Enabled = Not(Me.Approved)

HTH

Ian
 
Thanks for your reply, but it's not working. I put the code behind the oncurrent event on my form, but it disables the button before I even get to it. when I open my form the button is already disabled and the check mark is in. I want to be able to press the button and then it becomes disabled. Any other suggestion would be very helpful. Thanks
 
Try shifting the focus to another control on your form like Ian suggested before you disable it. Re-enable your Approved button in the on click event of nother button, or when you move forward one record.

You might also want to check you code to be sure that the enabled property is turned off when the field value is set to yes, it seems to me it is turned on when this is true.

I hope I made sense if not I apologize
 
This form that I am working on is a subform that has the approved button on it. I have already disabled the navigation buttons and the data on the form moves according to the major form. I have figured out how to able and disable the approve button, but now I have another problem. when I move to another record my approved button stays gray for other records. I have to close my form and come back to it in order for it to work. Do you have any suggestion to that? Thans for all of your help. This site has help me alot in the past couple of months.
smile.gif
 
You'll probably need to add some code to Form_Current to account for when you're just browsing through records.
 
Just to clarify things for other helpers,
Sohaila I believe has put the code I gave her in the OnCurrent event by mistake(or my poor explanation).- I have advised her via email about what code she put there and am waiting a response on whether she has resolved the problem or not.

Ian
 
Yes I got it on Friday Ian, Thanks for all your help. It's working like a charm. I even added the code for my subforms so when the user clicks the approved button the appropriate fields become gray and when they come back to the same record, the subforms disappear. Thanks again, I have been getting a lot of help from your site. When I am not that busy, I'm browsing Access World Forums. Thanks again,
Sohaila
smile.gif
 

Users who are viewing this thread

Back
Top Bottom