Report not printing correctly Part 2 (1 Viewer)

sprijohn

Registered User.
Local time
Yesterday, 20:05
Joined
Oct 11, 2018
Messages
14
Back in December I thought I had this solved. The contributed solutions work well except that in the final DB the reports print based on parameter queries. Occasionally this results in a single record. My dilemma is that we need the resulting sign-in sheet even if it just has one record printed on it.

What I am having difficulty with is that while it will print the single record it does not pad the sheet with blank rows unless there are 2 or more records in the query. I have attached my test DB with additional reports based on a query that provides only one record. Both the original report and my new problem report are called by the form "frmTestReports." On the form the button "Preview: PD-Sign-in Sheets 2" is the one that does not format correctly. Sheet 2 should look like sheet 1 except that sheet 2 has only one record. Through trial and error I have narrowed down the problem to Report2's VBA code where it resets the iLine counter to 0 when on the first record. How do I get the code to get out of this apparent loop since it only has one record and allow the report to fill in the missing lines with blanks?
 

Attachments

  • Blank_Lines_Test2.zip
    95.6 KB · Views: 69

JHB

Have been here a while
Local time
Today, 04:05
Joined
Jun 17, 2012
Messages
7,732
Replace what you've with the below:
Code:
  If Me.CurrentRecord = 1 Then
    If iTotal = 1 And iLine = 0 Then
      iLine = 0
      Me!LastName.ForeColor = vbBlack
      Me!FirstName.ForeColor = vbBlack
      Me!Position.ForeColor = vbBlack
      Me!Building.ForeColor = vbBlack
      Me!PTSBNumber.ForeColor = vbBlack
    End If
  End If
Then there is some wrong control name in your VBA code, you've spelled it "Postion" but actually it is "Position", but because you're using the worst error handler "On Error Resume Next" you're not getting an error.
 

Attachments

  • Blank_Lines_Test2.accdb
    648 KB · Views: 71

June7

AWF VIP
Local time
Yesterday, 18:05
Joined
Mar 9, 2014
Messages
5,465
This change in Detail_Form works as well:

If Me.CurrentRecord = 1 And iTotal <> 1 Then

However, I find that neither change works if the query returns no records, so better make sure the parameter input is valid.

Use dot . instead of bang ! when referencing controls and the intellisense popup tips will work. Also, Debug Compile would have exposed that typo.

I always name controls different from the field bound to, such as tbxPos.
 
Last edited:

sprijohn

Registered User.
Local time
Yesterday, 20:05
Joined
Oct 11, 2018
Messages
14
Success!!!

After trying both suggested solutions which stopped the loop but did not print the additional blank lines I spent several hours learning how to use the watches window. I discovered that the error was in the timing of resetting the iLine variable to zero. By remarking out the "iLine = 0" statement at the beginning of the subroutine and adding "If iLine = iRptLines then iLine = 0" immediately before the "End Sub" line the report now works perfectly regardless of the number of records provided by the source query.
 

Attachments

  • Blank_Lines_Test2-Fixed.zip
    99.4 KB · Views: 81

June7

AWF VIP
Local time
Yesterday, 18:05
Joined
Mar 9, 2014
Messages
5,465
Interesting, because I did get additional blank lines with both suggested changes.

Still does not print blank lines if the query does not retrieve records. Following change allows for empty recordset and produces 1 page full of blank rows.
Code:
  If iTotal Mod iLines = 0 Then
    iRptLines = IIf(iTotal = 0, 24, ((iTotal \ iLines)) * iLines)
  Else
    iRptLines = ((iTotal \ iLines) + 1) * iLines
  End If
If you like one-liners:

iRptLines = IIf(iTotal = 0, 24, ((iTotal \ iLines) + IIf(iTotal Mod iLines = 0, 0, 1)) * iLines)
 
Last edited:

sprijohn

Registered User.
Local time
Yesterday, 20:05
Joined
Oct 11, 2018
Messages
14
Sweet!!!!!!!!!

That worked like a charm! The report now works with any number of records from 0 to infinity (or until the toner or paper runs out).

Now the issue is really solved

Thank you again!
 

Users who are viewing this thread

Top Bottom