Lock A CheckBox After Clicking

g@v

Registered User.
Local time
Today, 17:52
Joined
Feb 14, 2005
Messages
14
Hi Guys,

I have a form which is called test and in there a have a button box. What I want to do is Disable that Button box (its not a tick box not sure if that makes any difference) after checking it...

http://www.access-programmers.co.uk/forums/showthread.php?t=81223

I have tried the above to no luck :confused: I do have a auto insert date macro in the after update would that matter?

Thanks for any help, Please let me know if you need more info im fairly new to this
 
Hi, Welcome to the forums..

I have a form which is called test and in there a have a button box. What I want to do is Disable that Button box (its not a tick box not sure if that makes any difference) after checking it...

It depends on what you want to do....



1. If you only want to disable the button after clicking it is fairly easy, but then everytime you step in a different record the command button will be back to its original state (enabled)

2. If you want to disable the button after is clicked and not let it to be enabled at all While the form is open .

3. If you want to perform a specific action and have access remember the state of the button for every record, then you have somehow to let Access know that the specific action took place so the command Button will be disabled everytime we step on that record.

I attached a simple example showing the 3 different cases.

This is the explanation

1. Just disable the button, once steping in a different record the button will go back to its original Enabled State.

This is button 1 on the example, on the "on Click" event of the button I put the following code

Code:
Private Sub cmdButton1_Click()
    Me.Record.SetFocus
    Me.cmdButton1.Enabled = False
End Sub

the first line is to send the focus anywhere else on the form, Access will not allow you to disable a control (button, box, etc) that has the focus.
The Second line, simply put, Disable the button.

and in the "on Current Event of the form I put the follwing Code:

Code:
Private Sub Form_Current()
    Me.cmdButton1.Enabled = True
    '-----------------------------------------------------------------
    If Me.Disable = -1 Then
        Me.cmdButton3.Enabled = False
    Else
        Me.cmdButton3.Enabled = True
    End If
End Sub

Just look at the first Line, above the dotted line, it will set the button to an enabled state everytime the user changes the record.


2. second Case: Button gets disabled as long as the form is open.

See Button2 , if you click it, it will stay disabled as long as Access is open.

Code:
Private Sub cmdButton2_Click()
    Me.Record.SetFocus
    Me.cmdButton2.Enabled = False
End Sub

Same code as first, this time we don't set it back to enabled on the OnCurrent event of the form

3. Third Case: BUtton is enabled/Disabled depending on an action performed on the record (most likely Case)

The button is disabled after clicking on it Access will remember the state of the button for every record.

For this, you have to add a colum in your table to let know access the state of the button, it will be a checkbox colum lets call that colum "Disable"

Code:
Private Sub cmdButton3_Click()
    Me.Disable = -1
    DoCmd.Requery
End Sub

What the first line does is to put a check on the checkbox everytime you click on the button. (-1 is equal to Checked, 0 is equal to Unchecked)
The second line will "refresh" the data on the form.

now we need to tell access how to interpret this info:

Code:
Private Sub Form_Current()
     Me.cmdButton1.Enabled = True
    '-----------------------------------------------------------------
    If Me.Disable = -1 Then
        Me.cmdButton3.Enabled = False
    Else
        Me.cmdButton3.Enabled = True
    End If
End Sub

Look bellow the dotted line:

this If /Else/ End if statement instruct access to disable the button if the checkbox is checked, otherwise to enable the button
given the fact that this code is placed in the On current event of the form every time the users select a different record Access will check if the condition is met and then take appropriate action.

See the attached Example

Sorry for this long Explanation, Hope it is clear.
 

Attachments

Last edited:
Gabriel - Thank you so much example 3 was just what I was after!

Thanks again for indepth reply!!!

g@v
 

Users who are viewing this thread

Back
Top Bottom