Check Box Question

G

Guest

I have the following code on the OnOpen property of the form.
Private Sub Form_Open(Cancel As Integer)

If Me.PAID = "-1" Then
Me.DATEPAID.Enabled = True
Me.AMOUNTPAID.Enabled = True
Me.PAYMENTTYPE.Enabled = True
Else
Me.DATEPAID.Enabled = False
Me.AMOUNTPAID.Enabled = False
Me.PAYMENTTYPE.Enabled = False
End If

End Sub

I want the DatePaid, AmountPaid, and PaymentType fields to be inactive
unless the PAID checkbox is checked. But once I check the box for one record,
the three gray fields become active for ALL records. How can I make it
specific to each individual record?

Also, once they are active, is there a way to make them a required field,
but not when they are inactive?
 
A

Al Camp

Jennie,
You need to use the OnCurrent event to trigger this code. As you come
to each record, PAID is evaluated, and the fields set properly.
Also, you'll need the same code on the AfterUpdate event of PAID. If you
set PAID True, those fields will enable/disable on the spot.
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions
 
G

Guest

You need to change the code to the below and put it in the On current event
of the form and not the onOpen. You will alos need to put it in the after
update event of the PAID checkbox.

If Me.PAID = False Then
Me.DATEPAID.Enabled = True
Me.AMOUNTPAID.Enabled = True
Me.PAYMENTTYPE.Enabled = True
Else
Me.DATEPAID.Enabled = False
Me.AMOUNTPAID.Enabled = False
Me.PAYMENTTYPE.Enabled = False
End If
 
G

Guest

Thanks! Works perfectly!

Dennis said:
You need to change the code to the below and put it in the On current event
of the form and not the onOpen. You will alos need to put it in the after
update event of the PAID checkbox.

If Me.PAID = False Then
Me.DATEPAID.Enabled = True
Me.AMOUNTPAID.Enabled = True
Me.PAYMENTTYPE.Enabled = True
Else
Me.DATEPAID.Enabled = False
Me.AMOUNTPAID.Enabled = False
Me.PAYMENTTYPE.Enabled = False
End If
 
F

fredg

Thanks! Works perfectly!

Besides being placed in the wrong event, your code would have failed
anyway.
This line:
If Me.PAID = "-1" Then
sets the value of -1 as a text value, which is incorrect. The value is
a Number.
If Me.PAID = -1 Then
would work (when placed in the correct events, as stated by Dennis).
Dennis's use of =False works because, in Access, False (without the
quotes) has a number value of -1.

An alternative method (less code) would be:

Me.DATEPAID.Enabled = Me!Paid
Me.AMOUNTPAID.Enabled = Me!Paid
Me.PAYMENTTYPE.Enabled = Me!Paid
 
F

fredg

Besides being placed in the wrong event, your code would have failed
anyway.
This line:
If Me.PAID = "-1" Then
sets the value of -1 as a text value, which is incorrect. The value is
a Number.
If Me.PAID = -1 Then
would work (when placed in the correct events, as stated by Dennis).
Dennis's use of =False works because, in Access, False (without the
quotes) has a number value of -1.

An alternative method (less code) would be:

Me.DATEPAID.Enabled = Me!Paid
Me.AMOUNTPAID.Enabled = Me!Paid
Me.PAYMENTTYPE.Enabled = Me!Paid

I inadvertently pressed the send button on my previous reply, just as
I realized an error in my post. Sorry.

I noticed an inconsistency in Dennis's and your posts.
In your original post you wanted to set the enabled properties to True
if the check box value is -1 (True). In Dennis's post he sets the
Enabled properties to True when the check box is False (which I then
unthinkingly carried on with my incorrect statement that "Dennis's use
of =False works because, in Access, False (without the quotes) has a
number value of -1.", which is incorrect. False has a value of 0, not
-1. So now I can't understand how you stated that Dennis code
'worked'.
 
G

Guest

I know, I changed it to TRUE, it worked, but the opposite of what I wanted.
It automatically made the fields active if the box was not checked. So the
code worked, just had to change that one word, now it works perfectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Check Box query issue 3
Access 2010 0
Make field Invisible/Visable 2
Disable recordset if check box true 1
Check Box Property 16
Check box question 2
Check Box 4
What event occurs After form record is loaded 2

Top