Print Preview Problem RRS feed

  • Question

  • Please,can someone help me ? I am trying to display the grade of student in print preview but it won't show. Here is what I did in report, I created a button with the following code in the event procedure:

    Dim GRADE As Integer

    If TxtAverage >= 0 And TxtAverage < 49.5 Then

    TxtGrade = "F"

    ElseIf TxtAverage >= 49.5 And TxtAverage < 54.5Then

    TxtGrade = "E"

    ElseIf TxtAverage >= 54.5 And TxtAverage < 64.5 Then

    TxtGrade = "D"

    ElseIf TxtAverage >= 64.5 And TxtAverage < 74.5 Then

    TxtGrade = "C"

    ElseIf TxtAverage >= 74.5 And TxtAverage < 84.5 Then

    TxtGrade = "B"

    ElseIf TxtAverage >= 84.5 And TxtAverage <= 100 Then

    TxtGrade = "A"


    TxtGrade = ""

    End If

    I also created a textbox to display the grade "TxtGrade " This code works in report view but it won't display the grade in print preview. I will be glad if solution is provided here.


    Friday, April 20, 2018 1:29 PM

All replies

  • Don't use code. Set the Control Source of TxtGrade to


    Regards, Hans Vogelaar (

    Friday, April 20, 2018 2:33 PM
  • PrintPreview mode is unable to process Events like ReportView can. So if you are opening the report in PrintPreview mode first, then it won't work. Assuming your code is executing properly after you click the button when you open the report in ReportView, you might try:

    1. Open the report in ReportView mode first
    2. Click the Event button so your code is executed
    3. Open the report in PrintPreview mode using DoCmd.RunCommand acCmdPrintPreview as the last VBA line in your code.
    Friday, April 20, 2018 2:37 PM
  •  Thanks so much,this code you sent to me,I had used it before, but the challenge I had then was that the "Grade" of one student will be shown all through on other students. That was why I did not use the Control Source. I want the "Grade" of each student to show on individual report. Please,I will appreciate if you can still help me out. Thank you.
    Friday, April 20, 2018 4:48 PM
  • Create a query based on the table, and add a calculated column to this query:

    TxtGrade: IIf([TxtAverage]<0,"",IIf([TxtAverage]<49.5,"F",IIf([TxtAverage]<54.5,"E",IIf([TxtAverage]<64.5,"D",IIf([TxtAverage]<74.5,"C",IIf([TxtAverage]<84.5,"B",IIf([TxtAverage]<=100,"A","")))))))

    Set the Record Source of the report to this query, and the Control Source of TxtGrade to the field of the same name.

    Regards, Hans Vogelaar (

    Friday, April 20, 2018 6:30 PM
  • Hard-coding data is bad relational database design.  A fundamental principle of the database relational model is the Information Principle (Codd's Rule #1). This requires that all data be stored as values at column positions in rows in tables, and in no other way.

    Firstly you should create a Grades table with the Grade column as its primary key and columns for the upper and lower limits of each grade.  You can then easily join a query which computes the average mark per student to the Grades table on the average mark falling between the lower and upper limit values.  The grade can then be returned in this query.

    However, the  lower and upper limit values are not necessarily time-independently determined by the key of Grades, so the computed grade per student should be assigned to a Grade column in the relevant table.  No redundancy ensues from this as the grade is functionally determined solely by the key of the relevant table.  A very common analogy is the inclusion of UnitPrice columns in OrderDetails and Products tables, where the value is again not  time-independently determined by the key of the referenced  table, Products in this case.

    It is then simply a matter of binding a control in the report to the Grade column in the referencing table, which is analogous to the OrderDetails table in the above example.  In this example the assignment is usually undertaken on a single row in the AfterUpdate event procedure of a ProductID control in an order detail subform (Northwind is an example).  In your case, however, the assignment would be more likely to be undertaken to the subset of row returned by the report, at some stage prior to the opening of the report.

    Ken Sheridan, Stafford, England

    Friday, April 20, 2018 10:22 PM
  • Hello Freddyparc,

    >>but the challenge I had then was that the "Grade" of one student will be shown all through on other students. 

    What do you mean this? Would you mind a screenshot/a simply database file to illustrates us the desired result or behavior we should do? 

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, April 23, 2018 8:48 AM