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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Box on a Form/Report 1

Status
Not open for further replies.

Stephenlyn

Programmer
May 25, 2000
34
AU
I have a program that is producing school reports for special needs kids. The kids can be assessed in different curriculun areas. So I have check boxes on the form to indicate what curriculum areas they are being assessed on.

When the report is called the following code is supposed to check the status of the check box and hide or show parts of the report.

Code:
Private Sub Report_Page()
DoCmd.RepaintObject


 If [cbxW7] = False Then
        [SentenceStructure].Visible = False
        [UseOfVocabulary].Visible = False
        [PunctuationGrammar].Visible = False
        [AppliesEditingSkills].Visible = False
        [Content].Visible = False
        [frmW1].Visible = False
        [frmW2].Visible = False
        [frmW3].Visible = False
        [frmW4].Visible = False
        [frmW5].Visible = False
        [txtW1_effort].Visible = False
        [txtW2_effort].Visible = False
        [txtW3_effort].Visible = False
        [txtW4_effort].Visible = False
        [txtW5_effort].Visible = False
        [lblWriting].Visible = False
    End If
     If [cbxR6] = False Then
        [Comprehension].Visible = False
        [WordKnowledge].Visible = False
        [OralReading].Visible = False
        [frmR1].Visible = False
        [frmR2].Visible = False
        [frmR3].Visible = False
        [txtR1_effort].Visible = False
        [txtR2_effort].Visible = False
        [txtR3_effort].Visible = False
        [READING].Visible = False
    End If

End Sub

The problem I have is the first record is always showing everything and other records sometimes behave correctly but offen behave what appears to be dependant on the previous record.

What do I need to do to make this work.

cheers
 
Try putting just the IF statements in the OnFormat event procedure of the Detail Section only. Remove it from the Report_Page event procedure. The Report_Page event executes after the OnFormat event procedure has already completed execution. It is really to be used to insert graphics type objects to the report. This is probably why you were getting weird results in your report.

Because you are analyzaing each record and modifying the visiblility of controls in the Detail Section it is in the OnFormat event procedure that you want to execute this code.

No need to include the Docmd.RepaintObject command.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
That's fixed the problem with the first record however the rest are still not behaving as they should. Any other ideas.
 
Please explain. The [cbxW7] and [cbxR6] are controls in your Report Detail Section? They change value for each Employee? They are boolean values?

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
yes that's right. It's a bound yes/no check box from the form that determines what is displaid on the report. each record can be different.
 
If that is the case then the following is how you reference those controls:

Code:
If FORMS![formname]![cbxW7] = False Then

If FORMS![formname]![cbxR6] = False Then

This VBA code should be put in the OnOpen Event procedure to setup the report for all records. Remove from the Detail Section.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
I don't call the report from the form.
While it's a control on the form it is also in the detail section of the report, so when you move from one record to another the check box may be different hence it should be hiding or showing different parts of the report page.

It's a 600k file, if you would like to have a look at it it is here


thanks
 
Okay, I see the problem. In your code in the Onformat event procedure you are checking two boolean fields for equal to False and setting the visible properties of the controls to false. Well, after you set the properties to false in the first record you don't have any code to set them back to visible if the next records value is True.

Example:

Code:
If [cbxW7] = False Then
        [SentenceStructure].Visible = False
        [UseOfVocabulary].Visible = False
        [PunctuationGrammar].Visible = False
        [AppliesEditingSkills].Visible = False
        [Content].Visible = False
        [frmW1].Visible = False
        [frmW2].Visible = False
        [frmW3].Visible = False
        [frmW4].Visible = False
        [frmW5].Visible = False
        [txtW1_effort].Visible = False
        [txtW2_effort].Visible = False
        [txtW3_effort].Visible = False
        [txtW4_effort].Visible = False
        [txtW5_effort].Visible = False
        [lblWriting].Visible = False
    Eles
         [green]'Here is you must set the above controls to True[/green]
[red]        [SentenceStructure].Visible = True
        [UseOfVocabulary].Visible = True
        [PunctuationGrammar].Visible = True
        [AppliesEditingSkills].Visible = True
        [Content].Visible = True
        [frmW1].Visible = True
        [frmW2].Visible = True
        [frmW3].Visible = True
        [frmW4].Visible = True
        [frmW5].Visible = True
        [txtW1_effort].Visible = True
        [txtW2_effort].Visible = True
        [txtW3_effort].Visible = True
        [txtW4_effort].Visible = True
        [txtW5_effort].Visible = True
        [lblWriting].Visible = True[/red]
    End If
     If [cbxR6] = False Then
        [Comprehension].Visible = False
        [WordKnowledge].Visible = False
        [OralReading].Visible = False
        [frmR1].Visible = False
        [frmR2].Visible = False
        [frmR3].Visible = False
        [txtR1_effort].Visible = False
        [txtR2_effort].Visible = False
        [txtR3_effort].Visible = False
        [READING].Visible = False
     Else
[red]        [Comprehension].Visible = True
        [WordKnowledge].Visible = True
        [OralReading].Visible = True
        [frmR1].Visible = True
        [frmR2].Visible = True
        [frmR3].Visible = True
        [txtR1_effort].Visible = True
        [txtR2_effort].Visible = True
        [txtR3_effort].Visible = True
        [READING].Visible = True [/red]       
    End If

Each record must be assessed and the controls visible property set to either True or False.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Your spot on. Now that you point it out the logic makes so much sense

It works a treat.

Thanks heaps Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top