AARRRGH! Need help w/ Yes/no control (1 Viewer)

ianacole

Registered User.
Local time
Today, 07:58
Joined
Nov 26, 2001
Messages
26
I'm having trouble finding the problem with the code below. It is in a subform, and I am trying to disable and lock fields based on the [Printed] check box (if yes (or checked) then lock fields). It seems that no matter what I do, the fields are either locked or unlocked, for both checked and unchecked boxes, not triggering on the criteria. Any help would be much appreciated.

Thanks,
Ian

Private Sub Form_Current()
If [Printed] = -1 Then
Purchaser.Locked = True
Purchaser.Enabled = False
CustNo.Locked = True
CustNo.Enabled = False
Recipient.Locked = True
Recipient.Enabled = False
Printed.Locked = True
Printed.Enabled = False
End If

If [Redeemed] = -1 Or [Refunded] = -1 Then
Redeemed.Enabled = False
Redeemed.Locked = True
Refunded.Enabled = False
Refunded.Locked = True
End If
End Sub
 

llkhoutx

Registered User.
Local time
Today, 01:58
Joined
Feb 26, 2001
Messages
4,018
Use the debugger to check what your code is doing. It appears ok.

Note that "Forms!Mainform!Subform!Printed" is better syntax that "[Printed]".

You indicate that your check box is on a subform. Your code must also be associated with the subform. The fields being locked/unlocked also appear to be on the subform. If not, that's your problem.
 

ianacole

Registered User.
Local time
Today, 07:58
Joined
Nov 26, 2001
Messages
26
Unfortunately, the debugger is not picking anything up...the code appears to be correct (that is why I am so baffled). This is a subform, and the code is against the subform, and the piece of code below to set the check box works perfectly (which is also in the subform). I am really stumped.

Dim stDocName As String
If [Printed] = 0 Then
stDocName = "IssueGiftCertificate"
DoCmd.OpenReport stDocName, acViewNormal, , "[GCNumber] =" & GCNumber

[Printed] = 1
Else
Exit Sub
End If
 

llkhoutx

Registered User.
Local time
Today, 01:58
Joined
Feb 26, 2001
Messages
4,018
If "[Printed]" is null, [Printed] <> 0, there, make your test

if nz([printed]) = 0 then . . .

You can test the value of [Printed} while in the subform with the debugger. Is it null, or 0?
 

ianacole

Registered User.
Local time
Today, 07:58
Joined
Nov 26, 2001
Messages
26
That did the trick, with some nuances. I set all the fields locked and disbled, then set the code to:

If Nz([Printed]) = 0 Then
Purchaser.Locked = False
Purchaser.Enabled = True
CustNo.Locked = False
CustNo.Enabled = True
Recipient.Locked = False
Recipient.Enabled = True
Printed.Locked = False
Printed.Enabled = True
PrintGC.Enabled = True
End If

It works now. Still not sure why it wouldn't work in the first instance, but I thank you for your direction. Helped me to get it to work, which is ultimately the goal!

Thank you again,

Ian
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:58
Joined
Feb 19, 2002
Messages
43,484
The problem is that you are only setting the properties in one case. Once you change the properties of the form, they stay changed until you change them again. You need to add an Else to the If so you can set the opposite states.

Private Sub Form_Current()
If [Printed] = -1 Then
Purchaser.Locked = True
Purchaser.Enabled = False
....
Else
Purchaser.Locked = False
Purchaser.Enabled = True
....
End IF

As llkhoutx pointed out, testing for true is better than testing for false since the false test as you have it coded would not properly handle null values.
 

ianacole

Registered User.
Local time
Today, 07:58
Joined
Nov 26, 2001
Messages
26
I originally had been testing for the "true", just as you stated. And, the debugger showed [printed] as equalling -1; that's what had me so confused. From previous actions in the code (setting printed to -1 when "Print" control button was depressed), I felt that the direction I took originally would work. I didn't include the else state because I didn't think I needed to reinforce the latent condition of the fields. I'm working in 2002, and seem to remember setting something similar in 2000, without including the else statement (but I could just be remembering a query). At one point during the testing, I had included the else condition, but to no avail. It did not seem to key off the -1 state of the checkbox. Oh well, all is working now, just another nuance to remember for future development. Thanks for the help.

Ian
 

Users who are viewing this thread

Top Bottom