Checkbox is set to Enabled (1 Viewer)

emilyebba

Registered User.
Local time
Yesterday, 16:40
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!
 

John Big Booty

AWF VIP
Local time
Today, 09:40
Joined
Aug 29, 2005
Messages
8,263
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.
 

emilyebba

Registered User.
Local time
Yesterday, 16:40
Joined
Sep 26, 2012
Messages
76
Thanks! That worked great!!!
 

emilyebba

Registered User.
Local time
Yesterday, 16:40
Joined
Sep 26, 2012
Messages
76
One more question. If say the user wanted to recheck the box...how would the Inactive date be cleared? Thanks!!
 

John Big Booty

AWF VIP
Local time
Today, 09:40
Joined
Aug 29, 2005
Messages
8,263
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]
 

emilyebba

Registered User.
Local time
Yesterday, 16:40
Joined
Sep 26, 2012
Messages
76
Hi..Thanks...where would you put:
Me.InactiveDate = ""
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 09:40
Joined
Jan 20, 2009
Messages
12,852
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
 

emilyebba

Registered User.
Local time
Yesterday, 16:40
Joined
Sep 26, 2012
Messages
76
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!
 

John Big Booty

AWF VIP
Local time
Today, 09:40
Joined
Aug 29, 2005
Messages
8,263
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 :eek: but it should be a simple matter to adjust it :)
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 09:40
Joined
Jan 20, 2009
Messages
12,852
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.
 

emilyebba

Registered User.
Local time
Yesterday, 16:40
Joined
Sep 26, 2012
Messages
76
Thanks so much Galaxiom and John Big Booty! Works great!
 

Users who are viewing this thread

Top Bottom