Checkbox is set to Enabled

emilyebba

Registered User.
Local time
Yesterday, 19:32
Joined
Sep 26, 2012
Messages
76
Hi,

I have a form where I have a check box that is ENABLED by default. However if a user un-checks it I would like it to enable a date field.

I have several checkboxes on my form that do the opposite..i.e. if you check it it ENABLES a field (by default the checkboxes are not enabled). To do this I use the following code:

Private Sub MgmtCo_AfterUpdate()

Me.MgmtCoList.Enabled = Me.MgmtCo

(the checkboxes are set to: Default value is False, Enabled Yes)

But I am having no luck with this checkbox that is ENABLED. I want the user to uncheck it and it enables a field. What do I do?

The Checkbox is called "ActiveCert" and the field I want to be enabled after you uncheck it is "InactiveDate"

Thanks!
 
Try;
Code:
If Me.ActiveCert = True Then
     Me.InactiveDate.Enabled = False
Else
     Me.InactiveDate.Enabled = True
End If

You will need this code in the Form's On Current event and the check box's On Click event.
 
Thanks! That worked great!!!
 
One more question. If say the user wanted to recheck the box...how would the Inactive date be cleared? Thanks!!
 
If you want to set it to today's date use;
Code:
Me.InactiveDate = [URL="http://www.techonthenet.com/access/functions/date/date.php"]Date()[/URL]
 
Hi..Thanks...where would you put:
Me.InactiveDate = ""
 
Another way to enable a control in response to the value of a different control is to use Conditional Formatting which has the added advantage of also working on Continuous Forms.

BTW This code from JBB is unnecessarily clumsy:
Code:
If Me.ActiveCert = True Then
     Me.InactiveDate.Enabled = False
Else
     Me.InactiveDate.Enabled = True
End If

This single line does exactly the same job:
Code:
Me.InactiveDate.Enabled = Not Me.ActiveCert
 
Hi, thanks! I would like to be able to have the date cleared if the Customer becomes Active again and the checkbox is rechecked....

Form automatically is checked for a new customer = Active
Date is grayed out

Unchecked = Inactive
Date is able to be filled in

Rechecked = Active
Whatever was in the date area clears out

Thanks!
 
You could use;
Code:
If Me.ActiveCert = True Then
     Me.InactiveDate.Enabled = False
     Me.InactiveDate = Date()
Else
     Me.InactiveDate.Enabled = True
     Me.InactiveDate = ""
End If

I think I have that they way you want :o but it should be a simple matter to adjust it :)
 
You might be interested in using a With block to make JBB's code tidier.
Code:
With Me.InactiveDate
     If Me.ActiveCert Then
          .Enabled = False
          .Value = Date()
     Else
          .Enabled = True
          .Value = ""
     End If
End With

Also note that it is unnecessary to test a boolean against True or False in an If construct.

If Me.ActiveCert = True Then

is the same as:

If Me.ActiveCert Then

BTW. If ActiveCert is being stored in the table then you might be breaching Normalization. If ActiveCert could be indicated by presence of a value in the InactiveDate field then the information is duplicated.
 
Thanks so much Galaxiom and John Big Booty! Works great!
 

Users who are viewing this thread

Back
Top Bottom