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!

Page Break does not work

Status
Not open for further replies.

colval

MIS
Feb 24, 2011
49
GB
Hi

we have a database that creates several records. We have a distribute button that creates HTML reports and one of these is meant to create a report that seperates each record in the report with a page break. The code below is as follows, (sorry about the lon code but trying to explain better

1. Code that the is in the template
2. Code once the report is made from the template

1.

<html>
<head>
<title>{!SurveyTitle!}</title>
{# UseFile report.css #}
<link rel="stylesheet" type="text/css" href="report.css"></link>
<basefont face="{!FontFace!}" size={!FontSize!}>
</head>
<body>

{# LoadQuery SELECT
TableSamples.SampleID,
GetSampleRefFromID(TableSamples.SampleID) As SampleRef,
TableSamples.SampleDate,
VListAreas.ItemValue As SampleArea,
VListFloors.ItemValue As SampleFloor,
TableSamples.SampleRoom,
VListComponents.ItemValue As SampleComponent,
TableSamples.SampleSurveyType,
ListAsbestosType.Description As SampleAsbestosType,
nz(ListAnalysis.Description,"NADIS") As SampleAnalysis,
nz(ListCondition.Description,"NADIS") As SampleCondition,
nz(ListFriability.Description,"NADIS") As SampleFriability,
nz(ListPosition.Description,"NADIS") As SamplePosition,
nz(ListTreatment.Description,"NADIS") As SampleTreatment,
TableSamples.SampleMaterialRisk,
MaterialRiskString(TableSamples.SampleMaterialRisk) As SampleMaterialRiskBand,
TableSamples.SamplePriorityRisk,
PriorityRiskString(TableSamples.SamplePriorityRisk) As SamplePriorityRiskBand,
TableSamples.SampleRecommendations,
VListLabs.ItemValue As SampleLab,
VListRemovalCosts.ItemValue As SampleRemovalCost,
VListNextInspectionDates.ItemValue As SampleNextInspectionDate,
VListActions.ItemValue As SampleAction,
TableSamples.SamplePhotoID,
TableSites.SiteSurveyorsName As SampleSurveyorsName
FROM (((((((((((((TableSamples
LEFT JOIN VListAreas ON TableSamples.SampleAreaID=VListAreas.ID)
LEFT JOIN VListFloors ON TableSamples.SampleFloorID=VListFloors.ID)
LEFT JOIN VListComponents ON TableSamples.SampleComponentID=VListComponents.ID)
LEFT JOIN ListAsbestosType ON TableSamples.SampleAsbestosTypeID=ListAsbestosType.ID)
LEFT JOIN ListAnalysis ON TableSamples.SampleAnalysisID=ListAnalysis.ID)
LEFT JOIN ListCondition ON TableSamples.SampleConditionID=ListCondition.ID)
LEFT JOIN ListFriability ON TableSamples.SampleFriabilityID=ListFriability.ID)
LEFT JOIN ListPosition ON TableSamples.SamplePositionID=ListPosition.ID)
LEFT JOIN ListTreatment ON TableSamples.SampleTreatmentID=ListTreatment.ID)
LEFT JOIN VListLabs ON TableSamples.SampleLabID=VListLabs.ID)
LEFT JOIN VListRemovalCosts ON TableSamples.SampleRemovalCostID=VListRemovalCosts.ID)
LEFT JOIN VListNextInspectionDates ON TableSamples.SampleNextInspectionDateID=VListNextInspectionDates.ID)
LEFT JOIN VListActions ON TableSamples.SampleActionID=VListActions.ID)
LEFT JOIN TableSites ON TableSamples.SampleSiteID=TableSites.SiteID
WHERE TableSamples.SampleSiteID={!SiteID!}
ORDER BY TableSamples.SampleID #}

{# ForEachRecord #}

{# IfNotFirstRecord #}
<p style="page-break-before: always"></p>
{# EndIf #}

<center><h3>MATERIAL AND PRIORITY ASSESSMENT RECORD</h3></center>

<table width=100% border=0>
<tr>
<td width=80 valign="top"><b><u>CLIENT</u></b></td><td valign="top">{!ClientAddress!}</td>
<td width=80 valign="top"><b><u>SITE</u></b></td><td valign="top">{!SiteAddress!}</td>
</tr>
</table>

<hr>

<table width=100% border=0 cellspacing=10>
<tr><td align="right" width=25%><b><u>SAMPLE REF.</u></b></td><td align="left" width=25%>{# InsertValue SampleRef #}</td>
<td align="right"" width=25%><b><u>SURVEY TYPE</u></b></td><td align="left" width=25%>T{# InsertValue SampleSurveyType #}</td></tr>

<tr><td align="right"><b><u>DATE TAKEN</u></b></td><td align="left">{# InsertValue SampleDate #}</td>
<td align="right"><b><u>ASBESTOS TYPE</u></b></td><td align="left">{# InsertValue SampleAsbestosType #}</td></tr>

<tr><td align="right"><b><u>AREA</u></b></td><td align="left">{# InsertValue SampleArea #}</td>
<td align="right" class="style1"><strong>PRODUCT TYPE</strong></td><td align="left">{# InsertValue SampleAnalysis #}</td></tr>

<tr><td align="right"><b><u>FLOOR</u></b></td><td align="left">{# InsertValue SampleFloor #}</td>
<td align="right"><b><u>CONDITION</u></b></td><td align="left">{# InsertValue SampleCondition #}</td></tr>

<tr><td align="right"><b><u>ROOM</u></b></td><td align="left">{# InsertValue SampleRoom #}</td>
<td align="right"><b><u>FRIABILITY</u></b></td><td align="left">{# InsertValue SampleFriability #}</td></tr>

<tr><td align="right"><b><u>COMPONENT</b></u></td><td align="left">{# InsertValue SampleComponent #}</td>
<td align="right"><b><u>POSITION</u></b></td><td align="left">{# InsertValue SamplePosition #}</td></tr>

<tr><td align="right"><b><u>SURVEYOR</b></u></td><td align="left">{# InsertValue SampleSurveyorsName #}</td>
<td align="right"><b><u>TREATMENT</u></b></td><td align="left">{# InsertValue SampleTreatment #}</td></tr>

<tr><td align="right"><b><u>LAB</b></u></td><td align="left">{# InsertValue SampleLab #}</td>
<td align="right"><b><u>MATERIAL RISK</u></b></td><td align="left"><b>{# InsertValue SampleMaterialRisk #} ({# InsertValue SampleMaterialRiskBand #})</b></td></tr>

<tr><td align="right"><b><u>NEXT INSPECTION</b></u></td><td align="left">{# InsertValue SampleNextInspectionDate #}</td>
<td align="right"><b><u>PRIORITY RISK</u></b></td><td align="left"><b>{# InsertValue SamplePriorityRisk #} ({# InsertValue SamplePriorityRiskBand #})</b></td></tr>

<tr><td align="right"><b><u>REMOVAL COST</b></u></td><td align="left" colspan=3>{# InsertValue SampleRemovalCost #}</td></tr>
<tr><td align="right"><b><u>ACTION</b></u></td><td align="left" colspan=3>{# InsertValue SampleAction #}</td></tr>

<tr><td align="center" colspan=4>{# InsertImage SamplePhotoID 15 8 #}</td></tr>

<tr><td align="center" colspan=4><b><u>RECOMMENDATIONS</b></u><br>{# InsertValue SampleRecommendations #}</td></tr>

</table>

{# InsertSampleDrawings SampleID #}

{# EndFor #}

<div class="pagefooter"><font face="arial" size=2 color=#808080><center>{!PageFooter!}</center></font></div></body>
</html>


2.

<html>
<head>
<title>Asbestos Survey Report for TEST</title>

<link rel="stylesheet" type="text/css" href="report.css"></link>
<basefont face="Arial" size=3>
</head>
<body>







<center><h3>MATERIAL AND PRIORITY ASSESSMENT RECORD</h3></center>

<table width=100% border=0>
<tr>
<td width=80 valign="top"><b><u>CLIENT</u></b></td><td valign="top">TEST</td>
<td width=80 valign="top"><b><u>SITE</u></b></td><td valign="top">TEST</td>
</tr>
</table>

<hr>

<table width=100% border=0 cellspacing=10>
<tr><td align="right" width=25%><b><u>SAMPLE REF.</u></b></td><td align="left" width=25%>1</td>
<td align="right"" width=25%><b><u>SURVEY TYPE</u></b></td><td align="left" width=25%>T1</td></tr>

<tr><td align="right"><b><u>DATE TAKEN</u></b></td><td align="left">09/03/2011</td>
<td align="right"><b><u>ASBESTOS TYPE</u></b></td><td align="left">NADIS</td></tr>

<tr><td align="right"><b><u>AREA</u></b></td><td align="left">Building 1</td>
<td align="right" class="style1"><strong>PRODUCT TYPE</strong></td><td align="left">NADIS</td></tr>

<tr><td align="right"><b><u>FLOOR</u></b></td><td align="left">External</td>
<td align="right"><b><u>CONDITION</u></b></td><td align="left">NADIS</td></tr>

<tr><td align="right"><b><u>ROOM</u></b></td><td align="left">Shed</td>
<td align="right"><b><u>FRIABILITY</u></b></td><td align="left">NADIS</td></tr>

<tr><td align="right"><b><u>COMPONENT</b></u></td><td align="left">Bitumen pad</td>
<td align="right"><b><u>POSITION</u></b></td><td align="left">NADIS</td></tr>

<tr><td align="right"><b><u>SURVEYOR</b></u></td><td align="left">&nbsp;</td>
<td align="right"><b><u>TREATMENT</u></b></td><td align="left">NADIS</td></tr>

<tr><td align="right"><b><u>LAB</b></u></td><td align="left">Inhouse Laboratory</td>
<td align="right"><b><u>MATERIAL RISK</u></b></td><td align="left"><b>0 (NADIS)</b></td></tr>

<tr><td align="right"><b><u>NEXT INSPECTION</b></u></td><td align="left">&nbsp;</td>
<td align="right"><b><u>PRIORITY RISK</u></b></td><td align="left"><b>0 (NFA)</b></td></tr>

<tr><td align="right"><b><u>REMOVAL COST</b></u></td><td align="left" colspan=3>N/A</td></tr>
<tr><td align="right"><b><u>ACTION</b></u></td><td align="left" colspan=3>No Action Required</td></tr>

<tr><td align="center" colspan=4><img src="dbimg137.jpg" style="width:5cm;"></td></tr>

<tr><td align="center" colspan=4><b><u>RECOMMENDATIONS</b></u><br>NA</td></tr>

</table>






<p style="page-break-before: always"></p>

<center><h3>MATERIAL AND PRIORITY ASSESSMENT RECORD</h3></center>

<table width=100% border=0>
<tr>
<td width=80 valign="top"><b><u>CLIENT</u></b></td><td valign="top">TEST</td>
<td width=80 valign="top"><b><u>SITE</u></b></td><td valign="top">TEST</td>
</tr>
</table>

<hr>

<table width=100% border=0 cellspacing=10>
<tr><td align="right" width=25%><b><u>SAMPLE REF.</u></b></td><td align="left" width=25%>2</td>
<td align="right"" width=25%><b><u>SURVEY TYPE</u></b></td><td align="left" width=25%>T1</td></tr>

<tr><td align="right"><b><u>DATE TAKEN</u></b></td><td align="left">09/03/2011</td>
<td align="right"><b><u>ASBESTOS TYPE</u></b></td><td align="left">Amosite</td></tr>

<tr><td align="right"><b><u>AREA</u></b></td><td align="left">Building 1</td>
<td align="right" class="style1"><strong>PRODUCT TYPE</strong></td><td align="left">Asbestos-reinforced composites</td></tr>

<tr><td align="right"><b><u>FLOOR</u></b></td><td align="left">External</td>
<td align="right"><b><u>CONDITION</u></b></td><td align="left">Low damage</td></tr>

<tr><td align="right"><b><u>ROOM</u></b></td><td align="left">Garage</td>
<td align="right"><b><u>FRIABILITY</u></b></td><td align="left">Low</td></tr>

<tr><td align="right"><b><u>COMPONENT</b></u></td><td align="left">Box panelling</td>
<td align="right"><b><u>POSITION</u></b></td><td align="left">External</td></tr>

<tr><td align="right"><b><u>SURVEYOR</b></u></td><td align="left">&nbsp;</td>
<td align="right"><b><u>TREATMENT</u></b></td><td align="left">None</td></tr>

<tr><td align="right"><b><u>LAB</b></u></td><td align="left">Inhouse Laboratory</td>
<td align="right"><b><u>MATERIAL RISK</u></b></td><td align="left"><b>4 (Very Low)</b></td></tr>

<tr><td align="right"><b><u>NEXT INSPECTION</b></u></td><td align="left">&nbsp;</td>
<td align="right"><b><u>PRIORITY RISK</u></b></td><td align="left"><b>0 (NFA)</b></td></tr>

<tr><td align="right"><b><u>REMOVAL COST</b></u></td><td align="left" colspan=3>N/A</td></tr>
<tr><td align="right"><b><u>ACTION</b></u></td><td align="left" colspan=3>No Action Required</td></tr>

<tr><td align="center" colspan=4><img src="dbimg138.JPG" style="width:6cm;"></td></tr>

<tr><td align="center" colspan=4><b><u>RECOMMENDATIONS</b></u><br>NA</td></tr>

</table>





<div class="pagefooter"><font face="arial" size=2 color=#808080><center>Asbestos risk management software - </html>



I cannot make out why it will not make the page break. I would appreciate any help on this. I feel it is something to do with the below but could be totally wrong.


<p style="page-break-before: always"></p>

<center><h3>MATERIAL AND PRIORITY ASSESSMENT RECORD</h3></center>


Hope someone can help..... Thanks
 
Sir,

Have you tried changing:

Code:
<p style="page-break-before: always"></p>


To:

Code:
<p style=page-break-before: "always"></p>

I'm not a very skilled web programmer but I am not used to seeing styles quoted like that.

I hope that helps.
 
Hi

colval said:
I cannot make out why it will not make the page break.
It works for me in Gecko, Presto, WebKit and KHTML. At least when using your template as HTML. Maybe when the HTML is generated and report.css is applied, things are changing, but you are the only able to find that out.

By the way, you know that the screen is a continuous media, while [tt]page-break-before[/tt] applies to paged media, right ?
candrid2 said:
I am not used to seeing styles quoted like that.
Then you should look at much more styles in the future. The syntax in colval's template is correct. And of course, your syntax is wrong.


Feherke.
 
Hi

Thanks for the replies

candrid2, i tried the quotes and got the same situation.

Feherke, not sure what gecko, presto etc.... are, but we generally use HTML and view in IE. It is using report.css i beleive but I have never used this so not sure how it is using it.
(any clues or files you may want to see)

What do you mean by continious media. I assume where the page break code is this is before the hearder so it should page break there, or if not how do I make it break.

This was written in access and as modules which when clicking an export button looks at the hltml templates (with select codes etc... on)and then creates the export files which as the information in it. In this case the Material Risk could ahve 3 records so what we expect is 3 files called mparecord1.html, mparecord2.html etc......

Any ideas....

Many Thanks
 
Hi

colval said:
Feherke, not sure what gecko, presto etc.... are, but we generally use HTML and view in IE.
Rendering engines. The heart of a browser.

As many browsers are using the same rendering engine, and their behavior is mainly influenced by the rendering engine, most of the time is enough to mention only those :
[ul]
[li]Gecko : FireFox, SeaMonkey, Camino, Gnuzilla, IceApe, IceCat, IceWeasel, Fennec, ...[/li]
[li]Presto : Opera, Opera Mini[/li]
[li]WebKit : Safari, Chrome, Epiphany, Midori, Arora, Rekonq, Uzbl, Android, ...[/li]
[li]KHTML : Konqueror[/li]
[li]Trident : Internet Explorer, AOL Explorer, Avant Browser, ...[/li]
[/ul]
However more and more browsers are using more than one rendering engine, but those are minor browsers.
colval said:
It is using report.css i beleive
I also believe that. That is what I tried to write there : your CSS works for me so far, but maybe just because I have no access to report.css.
colval said:
What do you mean by continious media.
Media where the content is displayed continuously, not split on pages.

Screen is continuous media ( some handheld device may be exception.
Printer is paged media.

[tt]page-break-before[/tt] is used on paged media.
colval said:
I assume where the page break code is this is before the hearder so it should page break there, or if not how do I make it break.
Correct. That is how it works on the browsers I tested it.


Feherke.
 
Ok losing me with scirence sorry lol

What do I need to do so it creates a page break for me.

Do you want to see the report.css and where do i find it.

Thanks
 
Hi

just found the code for the report.css

H3 {
text-decoration: underline;
page-break-after: ;
line-height: 2;
}

TABLE.assessment TD {
border-top-style: solid;
border-top-width: 1;
border-top-color: darkgray;
padding-top: 5;
font-size: 80%;
}

TABLE.samplerecord TD {
border-style: solid;
border-width: 1;
border-color: darkgray;
}

DIV.pagefooter {
display:none;
}

@media print {
DIV.pagefooter {
position:absolute;
bottom:0;
width:100%;
display:inline;
}
}


Thanks
 
Hi

colval said:
What do I need to do so it creates a page break for me.
Ok, short :
[ul]
[li]On printer : it should already be split on pages ( at least it is in the mentioned browsers )[/li]
[li]On screen : no way[/li]
[/ul]
That report.css contains nothing that could make the browser to not respect the [tt]page-break-before[/tt] rule.


Feherke.
 
Ok but when we print the report out (we usually import intoAdobe PDF and organise but, the Material Risk does not print on seperate pages at all.

What does the report.css do then?

thanks
 
Hi

colval said:
Ok but when we print the report out (we usually import intoAdobe PDF and organise but, the Material Risk does not print on seperate pages at all.
See the attached file, printed to file by FireFox. ( Size intentionally reduced to 50% to emphasize the page break. )

I would try with other browsers too. However it should work on Explorer too. ( The [tt]always[/tt] was the first supported value of [tt]page-break-before[/tt], however I not know since which version. )
colval said:
What does the report.css do then?
Sets the look of the
[ul]
[li]title ( approximately double line height )[/li]
[li]table cell ( unused )[/li]
[li]footer ( hides on screen, reveals on print )[/li]
[/ul]


Feherke.
 
Ok think I understand a little now.

I have taken the code it creates for the main file and put it into MS expression web, then viewed it in IE and firefox. I then printed to PDF and then it shows as two pages which is correct as it puts the page break where it should.

The process we use to Export from the access DB is to click on a button called Export full which then uses Event procedures to export. I will include the code below, just wondering if their is a clue in there. It should make a seperate HTML report for each material risk MParecord1 , mparecord2 etc.... and then we combine into PDF to make it all into one report. Presently it is putting all the Mparecords into one file and then when we turn into PDF we dont get the page breaks. Sorry its a lot of code.

Option Compare Database

Private Const REPORT_PAGE_WIDTH = 17

Private SurveySiteID As Integer
Private SurveySiteName As String
Private SurveySiteAddress As String
Private SurveyClientID As Integer
Private SurveyClientName As String
Private SurveyClientAddress As String

Dim ReportsRS As DAO.Recordset

Private PrintQueueSiteID As Integer
Private PrintQueueRS As DAO.Recordset

Public AutoPrinting As Boolean
Dim printerInterface As PageSet.PrinterControl

Function OpenSiteReport(SiteID As Integer, ReportID As Integer)
On Error Resume Next
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT ReportIsLandscape FROM TableReports WHERE ReportID=" & ReportID, dbOpenSnapshot)
Set printerInterface = New PrinterControl
If rs(0) = True Then
printerInterface.ChngOrientationLandscape
Else
printerInterface.ChngOrientationPortrait
End If
AutoPrinting = False
DoCmd.OpenForm "FormReport", , , , , , "PREVIEW:" & SiteID & ":" & ReportID
End Function

Function PrintSiteReport(SiteID As Integer, ReportID As Integer)
On Error Resume Next
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT ReportIsLandscape FROM TableReports WHERE ReportID=" & ReportID, dbOpenSnapshot)
Set printerInterface = New PrinterControl
If rs(0) = True Then
printerInterface.ChngOrientationLandscape
Else
printerInterface.ChngOrientationPortrait
End If
AutoPrinting = True
DoCmd.OpenForm "FormReport", , , , , acHidden, "PRINT:" & SiteID & ":" & ReportID
End Function

Function TestReportQueue()
If CurrentProject.AllForms!FormReport.IsLoaded Then Exit Function
If PrintQueueRS Is Nothing Then Exit Function
If PrintQueueRS.EOF Then
Application.Forms!FormSite.TimerInterval = 0
Set PrintQueueRS = Nothing
Set ReportsRS = Nothing
Set printerInterface = New PrinterControl
printerInterface.ReSetOrientation
DoCmd.Hourglass False
MsgBox "Full survey report has been sent to printer.", vbInformation + vbOKOnly, "Printing Complete"
Exit Function
End If
PrintSiteReport PrintQueueSiteID, PrintQueueRS(0)
PrintQueueRS.MoveNext
End Function

Function IncludeReport(ReportID As Long, reportName As String) As Boolean
IncludeReport = (MsgBox("Include " & reportName & " as part of survey report?", vbYesNo, "Optional Report") = vbYes)
End Function

Function PrintAllSiteReports(SiteID As Integer)
Cleanup
DoCmd.Hourglass True
Application.Forms!FormSite.OnTimer = "=TestReportQueue()"
Application.Forms!FormSite.TimerInterval = 8000
Set PrintQueueRS = CurrentDb.OpenRecordset("SELECT ReportID FROM TableReports WHERE ReportOptional = False OR IncludeReport(ReportID, ReportName) = True ORDER BY ReportID", dbOpenSnapshot)
Set ReportsRS = PrintQueueRS.Clone
PrintQueueSiteID = SiteID
End Function

Function ExportSiteReport(SiteID As Integer, ReportID As Integer)
Dim exportPath As String
Dim bCancelled As Boolean
exportPath = Mod_Custom.BrowseForPath("Export Path", FetchSetting("DefaultExportPath"), bCancelled)
If bCancelled Then Exit Function

If CreateSiteReport(SiteID, ReportID, exportPath) <> "" Then
MsgBox "Survey report has been successfully exported to '" & exportPath & "'.", vbInformation + vbOKOnly, "Export report"
Else
MsgBox "There were errors while exporting the survey report to '" & exportPath & "'.", vbInformation + vbOKOnly, "Export report"
End If
End Function

Function CreateSiteReport(SiteID As Integer, ReportID As Integer, FilePath As String, Optional bLandscape As Boolean) As String
On Error Resume Next

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT ReportID, ReportTemplateFile, ReportOutputFile, ReportIsLandscape FROM TableReports WHERE ReportID = " & ReportID, dbOpenSnapshot)
bLandscape = rs(3)
MkDir FilePath

InitSurvey SiteID
If WriteReport(rs(1), FilePath, rs(2)) Then
CreateSiteReport = FilePath & rs(2)
Else
CreateSiteReport = ""
End If
End Function

Function ExportAllSiteReports(SiteID As Integer)
On Error Resume Next

Dim exportPath As String
Dim bCancelled As Boolean
exportPath = BrowseForPath("Export Path", FetchSetting("DefaultExportPath"), bCancelled)
If bCancelled Then Exit Function

If CreateAllSiteReports(SiteID, exportPath) Then
MsgBox "Full survey report has been successfully exported to '" & exportPath & "'.", vbInformation + vbOKOnly, "Export survey"
Else
MsgBox "There were errors while exporting the full survey report to '" & exportPath & "'.", vbInformation + vbOKOnly, "Export survey"
End If
End Function

Function CreateAllSiteReports(SiteID As Integer, FilePath As String) As Boolean
On Error Resume Next
DoCmd.Hourglass True

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT ReportID, ReportTemplateFile, ReportOutputFile FROM TableReports WHERE ReportOptional = False OR IncludeReport(ReportID,ReportName) = True", dbOpenSnapshot)
Set ReportsRS = rs.Clone
MkDir FilePath

Dim FullSuccess As Boolean
FullSuccess = True

InitSurvey SiteID
Do While Not rs.EOF
If Not WriteReport(rs(1), FilePath, rs(2)) Then FullSuccess = False
rs.MoveNext
Loop

Set ReportsRS = Nothing

DoCmd.Hourglass False
CreateAllSiteReports = FullSuccess
End Function

Function InitSurvey(SiteID As Integer)
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT TableSites.SiteName, TableClients.ClientID, TableClients.ClientCompanyName FROM TableSites INNER JOIN TableClients ON TableSites.SiteClientID=TableClients.ClientID WHERE TableSites.SiteID = " & SiteID, dbOpenSnapshot)

SurveySiteID = SiteID
SurveySiteName = rs(0)
SurveySiteAddress = FormatForHTML(GetSiteAddress(SurveySiteID))
SurveyClientID = rs(1)
SurveyClientName = rs(2)
SurveyClientAddress = FormatForHTML(GetClientAddress(SurveyClientID))
End Function

Function FormatForHTML(PlainText As Variant) As String
If IsNull(PlainText) Or PlainText = "" Then FormatForHTML = "&nbsp;" _
Else FormatForHTML = Replace(PlainText, vbCrLf, "<br>" & vbCrLf, , , vbTextCompare)
End Function

Function WriteReport(TemplateFile As String, TargetPath As String, TargetFile As String) As Boolean
Dim TemplateData As String
Dim ReportData As String
ReportData = ""

On Error GoTo HandleOpenTemplateError

Close #3
Open GetTemplateDirectory() & TemplateFile For Input Access Read As #3
TemplateData = Input$(LOF(3), 3)
Close #3

On Error GoTo HandleError

Dim cmd As Variant
cmd = Array("", "Initial parsing", "")

TemplateData = Replace(TemplateData, "{!SurveyTitle!}", FetchSetting("SurveyTitle"), , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!CompanyName!}", FetchSetting("CompanyName"), , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!CompanyAddress!}", FormatForHTML(FetchSetting("CompanyAddress")), , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!CompanyLogoID!}", FetchSetting("CompanyLogoID"), , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!FontFace!}", FetchSetting("SurveyFontFace"), , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!FontSize!}", FetchSetting("SurveyFontSize"), , , vbTextCompare)

TemplateData = Replace(TemplateData, "{!Date!}", Date, , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!PageFooter!}", FormatForHTML(FetchSetting("PageFooter")), , , vbTextCompare)

TemplateData = Replace(TemplateData, "{!SiteID!}", Str$(SurveySiteID), , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!SiteName!}", SurveySiteName, , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!SiteAddress!}", SurveySiteAddress, , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!ClientID!}", Str$(SurveyClientID), , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!ClientName!}", SurveyClientName, , , vbTextCompare)
TemplateData = Replace(TemplateData, "{!ClientAddress!}", SurveyClientAddress, , , vbTextCompare)

Dim forIndex As Long
forIndex = 0
Dim rs As DAO.Recordset
Dim drawings As DAO.Recordset
Dim imgfile As String
Dim imgsize As Collection
Dim imgscale As Single
Dim c, t As Integer
Dim cmdIndex, cmdIndexEnd As Long
Dim lastValue As Variant
Dim skipFor, skipIf As Boolean
lastValue = ""
skipFor = False
skipIf = False
cmdIndexEnd = 1
cmdIndex = InStr(1, TemplateData, "{#", vbTextCompare)
Do While cmdIndex > 0
If Not skipFor And Not skipIf Then ReportData = ReportData & Mid(TemplateData, cmdIndexEnd, cmdIndex - cmdIndexEnd)
cmdIndex = cmdIndex + 2
cmdIndexEnd = InStr(cmdIndex, TemplateData, "#}", vbTextCompare)
If cmdIndexEnd > 0 Then
cmd = Split(Trim(Mid(TemplateData, cmdIndex, cmdIndexEnd - cmdIndex)), " ", 2, vbTextCompare)
If skipFor And cmd(0) <> "EndFor" Then GoTo SkipCmd
If skipIf And cmd(0) <> "EndIf" Then GoTo SkipCmd
Select Case cmd(0)
Case "UseFile"
If UBound(cmd) < 1 Then Err.Raise vbObjectError + 103, , "No filename found after UseFile"
Dim srcloc As String
Dim targetloc As String
srcloc = GetTemplateDirectory() & cmd(1)
targetloc = TargetPath & cmd(1)
If srcloc <> targetloc Then
FileCopy srcloc, targetloc
End If
Case "LoadQuery"
If UBound(cmd) < 1 Then Err.Raise vbObjectError + 103, , "No SQL statement found after LoadQuery"
Set rs = CurrentDb.OpenRecordset(cmd(1), dbOpenSnapshot)
Case "InsertValue"
If UBound(cmd) < 1 Then Err.Raise vbObjectError + 103, , "No field name found for InsertValue"
If rs Is Nothing Then Err.Raise vbObjectError + 104, , "Tried to insert field value without first loading query"
ReportData = ReportData & FormatForHTML(rs(cmd(1)))
Case "InsertImage"
If UBound(cmd) < 1 Then Err.Raise vbObjectError + 103, , "No field name found for InsertImage"
If rs Is Nothing Then Err.Raise vbObjectError + 104, , "Tried to insert field image without first loading query"
subcmd = Split(cmd(1), " ", 3, vbTextCompare)
If UBound(subcmd) < 2 Then Err.Raise vbObjectError + 103, , "No width and/or height given for InsertImage"
imgfile = Mod_Images.LoadImage(Nz(rs(subcmd(0)), 0), TargetPath)
If imgfile <> "" And getPictureSize(imgfile, imgsize) Then
ReportData = ReportData & "<img src=""" & Dir(imgfile) & """"
imgscale = 1
If (imgscale * imgsize("width")) > Val(subcmd(1)) Then imgscale = Val(subcmd(1)) / imgsize("width")
If (imgscale * imgsize("height")) > Val(subcmd(2)) Then imgscale = Val(subcmd(2)) / imgsize("height")
ReportData = ReportData & " style=""width:" & Int(imgscale * imgsize("width")) & "cm;"""
ReportData = ReportData & ">"
End If
Case "InsertImageByID"
If UBound(cmd) < 1 Then Err.Raise vbObjectError + 103, , "No Image ID found for InsertImageByID"
subcmd = Split(cmd(1), " ", 3, vbTextCompare)
If UBound(subcmd) < 2 Then Err.Raise vbObjectError + 103, , "No width and/or height given for InsertImageByID"
imgfile = Mod_Images.LoadImage(Val(subcmd(0)), TargetPath)
If imgfile <> "" And getPictureSize(imgfile, imgsize) Then
ReportData = ReportData & "<img src=""" & Dir(imgfile) & """"
imgscale = 1
If (imgscale * imgsize("width")) > Val(subcmd(1)) Then imgscale = Val(subcmd(1)) / imgsize("width")
If (imgscale * imgsize("height")) > Val(subcmd(2)) Then imgscale = Val(subcmd(2)) / imgsize("height")
ReportData = ReportData & " style=""width:" & Int(imgscale * imgsize("width")) & "cm;"""
ReportData = ReportData & ">"
End If
Case "InsertSampleDrawings"
If UBound(cmd) < 1 Then Err.Raise vbObjectError + 103, , "No Sample ID found for InsertSampleDrawings"
Dim SampleID As Long
SampleID = Nz(rs(cmd(1)), 0)
Set drawings = CurrentDb.OpenRecordset("SELECT DrawingImageID FROM TableSampleDrawings WHERE DrawingSampleID = " & SampleID, dbOpenSnapshot)
c = 0
If drawings.BOF Then
t = 0
Else
drawings.MoveLast
drawings.MoveFirst
t = drawings.RecordCount
End If
Do While Not drawings.EOF
c = c + 1
imgfile = Mod_Images.LoadImage(drawings(0), TargetPath)
If imgfile <> "" And getPictureSize(imgfile, imgsize) Then
ReportData = ReportData & "<center><p style=""page-break-before: always""><b>Sample Ref.: " & SampleID & " (drawing " & c & " of " & t & ")</b></p><img src=""" & Dir(imgfile) & """"
If imgsize("width") > REPORT_PAGE_WIDTH Then ReportData = ReportData & " style=""width:" & REPORT_PAGE_WIDTH & "cm"""
ReportData = ReportData & "></center>" & vbCrLf
End If
drawings.MoveNext
Loop
drawings.Close
Case "InsertSiteDrawings"
Set drawings = CurrentDb.OpenRecordset("SELECT DrawingImageID, DrawingDescription FROM TableSiteDrawings WHERE DrawingSiteID = " & SurveySiteID, dbOpenSnapshot)
c = 0
If drawings.BOF Then
t = 0
Else
drawings.MoveLast
drawings.MoveFirst
t = drawings.RecordCount
End If
Do While Not drawings.EOF
c = c + 1
imgfile = Mod_Images.LoadImage(drawings(0), TargetPath)
If imgfile <> "" And getPictureSize(imgfile, imgsize) Then
ReportData = ReportData & "<center><p style=""page-break-before: always""><b>Site Drawing " & c & " of " & t & ":<br>" & drawings(1) & "</b></p><img src=""" & Dir(imgfile) & """"
If imgsize("width") > REPORT_PAGE_WIDTH Then ReportData = ReportData & " style=""width:" & REPORT_PAGE_WIDTH & "cm"""
ReportData = ReportData & "></center>" & vbCrLf
End If
drawings.MoveNext
Loop
ReportData = ReportData & "<p style=""page-break-after: always""></p>"
drawings.Close
Case "IfDifferentValue"
If UBound(cmd) < 1 Then Err.Raise vbObjectError + 103, , "No field name found for IfDifferentValue"
If rs Is Nothing Then Err.Raise vbObjectError + 104, , "Tries to test field value without first loading query"
If rs(cmd(1)) = lastValue Then
skipIf = True
Else
lastValue = rs(cmd(1))
End If
Case "IfNotFirstRecord"
If rs Is Nothing Then Err.Raise vbObjectError + 104, , "Tries to test record number without first loading query"
If rs.AbsolutePosition = 0 Then
skipIf = True
End If
Case "IfReportIncluded"
If UBound(cmd) < 1 Then Err.Raise vbObjectError + 103, , "No report number specified for IfReportIncluded"
If ReportsRS Is Nothing Then
Dim reportName As DAO.Recordset
Set reportName = CurrentDb.OpenRecordset("SELECT ReportName FROM TableReports WHERE ReportID=" & cmd(1), dbOpenSnapshot)
skipIf = (MsgBox("Assume inclusion of " & reportName(0) & " in survey report?", vbYesNo, "Report Format Assumption") = vbNo)
Else
ReportsRS.FindFirst "ReportID = " & cmd(1)
If ReportsRS.NoMatch Then
skipIf = True
End If
End If
Case "EndIf"
skipIf = False
Case "ForEachRecord"
forIndex = cmdIndexEnd
rs.MoveFirst
If rs.EOF Then skipFor = True
Case "EndFor"
If skipFor Then
skipFor = False
Else
If forIndex < 1 Then Err.Raise vbObjectError + 105, , "EndFor without ForEachRecord"
rs.MoveNext
If rs.EOF Then
forIndex = 0
Else
cmdIndexEnd = forIndex
cmdIndex = cmdIndexEnd
End If
End If
Case Else
Err.Raise vbObjectError + 102, , "Command '" & cmd(0) & "' is unrecognised"
End Select
Else
Err.Raise vbObjectError + 101, , "{# found without matching #}"
End If
SkipCmd:
cmdIndexEnd = cmdIndexEnd + 2
cmdIndex = InStr(cmdIndex, TemplateData, "{#", vbTextCompare)
Loop
ReportData = ReportData & Mid(TemplateData, cmdIndexEnd)

On Error GoTo HandleWriteFileError

Close #4
Open TargetPath & TargetFile For Output Access Write As #4
Print #4, ReportData
Close #4

WriteReport = True
Exit Function
HandleOpenTemplateError:
MsgBox "Error reading from template file '" & TemplateFile & "':" & vbCrLf & Err.Description, vbExclamation + vbOKOnly, "Template File Error"
WriteReport = False
Exit Function
HandleWriteFileError:
MsgBox "Error writing to output file '" & TargetPath & TargetFile & "':" & vbCrLf & Err.Description, vbExclamation + vbOKOnly, "Output File Error"
WriteReport = False
Exit Function
HandleError:
MsgBox "Error while parsing " & TemplateFile & ":" & vbCrLf & Err.Description & vbCrLf & vbCrLf & "Current Command: """ & Join(cmd, " ") & """", vbExclamation + vbOKOnly, "Template Parsing Error"
WriteReport = False
End Function





 
Hi

Sorry, I know absolutely nothing about Access and VisualBasic ( I guess that is the language of your code ).

As I imagine how things work, the PDF generator class will probably not be influenced by CSS in the calculation of page breaks. But of course I could be wrong. Anyway I would ask in forum705.
colval said:
Sorry its a lot of code.
No problem with the length. Just please place [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] TGML tags around the code. Improves readability.


Feherke.
 
Ok I willt ry in the Forum you suggest.

Thanks for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top