Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

YES/NO ENABLE DISABLE 1

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
US
Here is my problem: When a certain yes/no box is true (checked) other fields on the form are not enabled. That works just find when I am on the record that I click the yes/no field. When I go to another record and then go back to the previous record the fields that should be disabled due to a certain yes/no box being true are now enabled and not disabled. Below is my code. Can anyone tell me what I am doing wrong?

Private Sub Form_Current()

SetCheckBoxes

End Sub

Private Sub SetCheckBoxes()

If Me.StaPrimary = True Then
Me.StaUp.Enabled = False
Me.StaUpTrainerFirstName.Enabled = False
Me.StaUpTrainerLastName.Enabled = False
Me.StaUpVerifyDate.Enabled = False
Me.StaUpReverifyDate.Enabled = False
Me.StaBack.Enabled = False
Me.StaBackTrainerFirstName.Enabled = False
Me.StaBackTrainerLastName.Enabled = False
Me.StaBackVerifyDate.Enabled = False
Me.StaBackReverifyDate.Enabled = False
Me.StaOther.Enabled = False
Me.StaOtherTrainerFirstName.Enabled = False
Me.StaOtherTrainerLastName.Enabled = False
Me.StaOtherVerifyDate.Enabled = False
Me.StaOtherReverifyDate.Enabled = False
End If

If Me.StaPrimary = False Then
Me.StaUp.Enabled = True
Me.StaUpTrainerFirstName.Enabled = True
Me.StaUpTrainerLastName.Enabled = True
Me.StaUpVerifyDate.Enabled = True
Me.StaUpReverifyDate.Enabled = True
Me.StaBack.Enabled = True
Me.StaBackTrainerFirstName.Enabled = True
Me.StaBackTrainerLastName.Enabled = True
Me.StaBackVerifyDate.Enabled = True
Me.StaBackReverifyDate.Enabled = True
Me.StaOther.Enabled = True
Me.StaOtherTrainerFirstName.Enabled = True
Me.StaOtherTrainerLastName.Enabled = True
Me.StaOtherVerifyDate.Enabled = True
Me.StaOtherReverifyDate.Enabled = True
Me.StaPrimaryVerifyDate = ""
Me.StaPrimaryReVerifyDate = ""

End If

If Me.StaUp = True Then
Me.StaPrimary.Enabled = False
Me.StaPrimaryTrainerFirstName.Enabled = False
Me.StaPrimaryTrainerLastName.Enabled = False
Me.StaPrimaryVerifyDate.Enabled = False
Me.StaPrimaryReVerifyDate.Enabled = False
Me.StaBack.Enabled = False
Me.StaBackTrainerFirstName.Enabled = False
Me.StaBackTrainerLastName.Enabled = False
Me.StaBackVerifyDate.Enabled = False
Me.StaBackReverifyDate.Enabled = False
Me.StaOther.Enabled = False
Me.StaOtherTrainerFirstName.Enabled = False
Me.StaOtherTrainerLastName.Enabled = False
Me.StaOtherVerifyDate.Enabled = False
Me.StaOtherReverifyDate.Enabled = False
End If

If Me.StaUp = False Then
Me.StaPrimary.Enabled = True
Me.StaPrimaryTrainerFirstName.Enabled = True
Me.StaPrimaryTrainerLastName.Enabled = True
Me.StaPrimaryVerifyDate.Enabled = True
Me.StaPrimaryReVerifyDate.Enabled = True
Me.StaBack.Enabled = True
Me.StaBackTrainerFirstName.Enabled = True
Me.StaBackTrainerLastName.Enabled = True
Me.StaBackVerifyDate.Enabled = True
Me.StaBackReverifyDate.Enabled = True
Me.StaOther.Enabled = True
Me.StaOtherTrainerFirstName.Enabled = True
Me.StaOtherTrainerLastName.Enabled = True
Me.StaOtherVerifyDate.Enabled = True
Me.StaOtherReverifyDate.Enabled = True
Me.StaUpVerifyDate = ""
Me.StaUpReverifyDate = ""

End If

If Me.StaBack = True Then
Me.StaPrimary.Enabled = False
Me.StaPrimaryTrainerFirstName.Enabled = False
Me.StaPrimaryTrainerLastName.Enabled = False
Me.StaPrimaryVerifyDate.Enabled = False
Me.StaPrimaryReVerifyDate.Enabled = False
Me.StaUp.Enabled = False
Me.StaUpTrainerFirstName.Enabled = False
Me.StaUpTrainerLastName.Enabled = False
Me.StaUpVerifyDate.Enabled = False
Me.StaUpReverifyDate.Enabled = False
Me.StaOther.Enabled = False
Me.StaOtherTrainerFirstName.Enabled = False
Me.StaOtherTrainerLastName.Enabled = False
Me.StaOtherVerifyDate.Enabled = False
Me.StaOtherReverifyDate.Enabled = False
End If

If Me.StaBack = False Then
Me.StaPrimary.Enabled = True
Me.StaPrimaryTrainerFirstName.Enabled = True
Me.StaPrimaryTrainerLastName.Enabled = True
Me.StaPrimaryVerifyDate.Enabled = True
Me.StaPrimaryReVerifyDate.Enabled = True
Me.StaUp.Enabled = True
Me.StaUpTrainerFirstName.Enabled = True
Me.StaUpTrainerLastName.Enabled = True
Me.StaUpVerifyDate.Enabled = True
Me.StaUpReverifyDate.Enabled = True
Me.StaOther.Enabled = True
Me.StaOtherTrainerFirstName.Enabled = True
Me.StaOtherTrainerLastName.Enabled = True
Me.StaOtherVerifyDate.Enabled = True
Me.StaOtherReverifyDate.Enabled = True
Me.StaBackVerifyDate = ""
Me.StaBackReverifyDate = ""

End If

If Me.StaOther = True Then
Me.StaPrimary.Enabled = False
Me.StaPrimaryTrainerFirstName.Enabled = False
Me.StaPrimaryTrainerLastName.Enabled = False
Me.StaPrimaryVerifyDate.Enabled = False
Me.StaPrimaryReVerifyDate.Enabled = False
Me.StaUp.Enabled = False
Me.StaUpTrainerFirstName.Enabled = False
Me.StaUpTrainerLastName.Enabled = False
Me.StaUpVerifyDate.Enabled = False
Me.StaUpReverifyDate.Enabled = False
Me.StaBack.Enabled = False
Me.StaBackTrainerFirstName.Enabled = False
Me.StaBackTrainerLastName.Enabled = False
Me.StaBackVerifyDate.Enabled = False
Me.StaBackReverifyDate.Enabled = False
End If

If Me.StaOther = False Then
Me.StaPrimary.Enabled = True
Me.StaPrimaryTrainerFirstName.Enabled = True
Me.StaPrimaryTrainerLastName.Enabled = True
Me.StaPrimaryVerifyDate.Enabled = True
Me.StaPrimaryReVerifyDate.Enabled = True
Me.StaUp.Enabled = True
Me.StaUpTrainerFirstName.Enabled = True
Me.StaUpTrainerLastName.Enabled = True
Me.StaUpVerifyDate.Enabled = True
Me.StaUpReverifyDate.Enabled = True
Me.StaBack.Enabled = True
Me.StaBackTrainerFirstName.Enabled = True
Me.StaBackTrainerLastName.Enabled = True
Me.StaBackVerifyDate.Enabled = True
Me.StaBackReverifyDate.Enabled = True
Me.StaOtherVerifyDate = ""
Me.StaOtherReverifyDate = ""

End If

End Sub
 
I don't see a refresh anywhere in your coding after the if..end routines. Could this be the problem?


Program Error
Programmers do it one finger at a time!
 
I do not know?? I am seeking the answer. When I change forms and then go back to an old form I would think each time I go back the code should apply.
 
Why not try putting a break point in your code and step thru the code to see waht is happening

Also, just to make it easire to understand how about using IF ...Then

Else

End If

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
As an aside you could remove the If statements.

Since the Enabled property is set to the opposite of the check box, you could, for example use:

Me.StaUp.Enabled = Not Me.StaPrimary
Me.StaUpTrainerFirstName.Enabled = Not Me.StaPrimary
...
...

and the date fields are blanked when the checkbox is unchecked, so:

Me.StaPrimaryVerifyDate = IIf(Me.StaPrimary,Me.StaPrimaryVerifyDate, "")
Me.StaPrimaryReVerifyDate = IIf(Me.StaPrimary,Me.StaPrimaryReVerifyDate, "")
...
...

This would half the amount of code that yoou have to maintain.

Other than that I can not see anything wrong with your code, although Refresh as suggested by ProgramError wouldn't hurt.

Hope ths helps.
 
Where would I put the Refresh code????

I will try these solutions and thanks a lot.
 
In OnCurrent, after the call to SetCheckBoxes or before End Sub in SetCheckBoxes.

Hope this helps.
 
Hi!

Are StaPrimary, StaUp and StaBack fields in a table or just text boxes on the form? Unless they are stored in the record sourse of the form then, when you move from record to record the default value of the check boxes will be used for the value of the check boxes. If you want the values last used to be there again when you navigate, you need to store the values.

hth


Jeff Bridgham
bridgham@purdue.edu
 
just try docmd.refresh at the end of your code, and on form afterupdate. See what that does

misscrf

It is never too late to become what you could have been ~ George Eliot
 
Everyone:

I have tried everything suggested and nothing is working. Any other suggestions out there?
 
You say nothing is working but you haven't said what does happen.


Randy
 
Try to start from scratch in an empty DB,
Create a table with a Identity, checkbox and a field

Create a form for it and in your Form_Current call
Me.Fieldname.Enabled = Not Me.Checkbox

Works fine for me.

Also, if you've got a load of options to turn on / off

You might consider rewriting your code a bit to make it better readable and shorter:

Private Sub Form_Current
If
(Me.StaPrimary Or Me.StaUp Or
Me.StaBack Or Me.StaOther)
then
SetCheckBoxes(True)
Else
setCheckBoxes(False)
End If
End Sub

Private Sub SetCheckBoxes(blnValue as Boolean)
Me.StaPrimary.Enabled = blnValue
Me.StaPrimaryTrainerFirstName.Enabled = blnValue
Me.StaPrimaryTrainerLastName.Enabled = blnValue
Me.StaPrimaryVerifyDate.Enabled = blnValue
Me.StaPrimaryReVerifyDate.Enabled = blnValue
Me.StaUp.Enabled = blnValue
Me.StaUpTrainerFirstName.Enabled = blnValue
Me.StaUpTrainerLastName.Enabled = blnValue
Me.StaUpVerifyDate.Enabled = blnValue
Me.StaUpReverifyDate.Enabled = blnValue
Me.StaBack.Enabled = blnValue
Me.StaBackTrainerFirstName.Enabled = blnValue
Me.StaBackTrainerLastName.Enabled = blnValue
Me.StaBackVerifyDate.Enabled = blnValue
Me.StaBackReverifyDate.Enabled = blnValue
If blnValue then
Me.StaOtherVerifyDate = ""
Me.StaOtherReverifyDate = ""
Else
Me.StaOtherVerifyDate.Enabled = blnValue
Me.StaOtherReverifyDate.Enabled= blnValue
End If



Or even better, use a Tab control or loop through all the controls of the form using something like:
For Each ctl In Forms(Forms.Count - 1).Controls...

"In three words I can sum up everything I've learned about life: it goes on."
- Robert Frost 1874-1963
 
Randy,

What does happen is in the original post. When I navigate off the current form and then go back to an existing form the fields that should be disabled due to one of the yes/no boxes being checked or enabled.
 
Good advice DaOth

Never give up never give in.

There are no short cuts to anything worth doing :)
 
netrusher,

I can think of only three reasons that would explain the behavior you have described:

1) The checkboxes are not bound to the recordsource.
2) There is other code running which is somehow altering, cancelling or undoing the checkboxes.
3) Corrupt database.

I think earthandfire has given excellent advice, I would not use If..Then statements in this context, I would simply set the visible or enabled property by direct reference to the value of the appropriate checkbox; will cut your code in half. DaOth offers a good variation, also.

If you've checked everything and it still won't work, create a small test table and form to get just this part working. Break it down into small, bite-size pieces, then apply it to the larger project.

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top