Public Sub PrintReport(ReportType As String)
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim fn As String
Dim Path As String
Select Case ReportType
Case "1"
fn = "C:\QA\Templates\Core Power Cable.docx"
Case "2"
fn = "C:\QA\Templates\Core Control Cable.dotx"
Case "3"
fn = "C:\QA\Templates\Core Earth Test Sheet.dotx"
Case "4"
fn = "C:\QA\Templates\Core Test Motor Test Sheet.dotx"
Case "5"
fn = "C:\QA\Templates\Core Instrument Test Sheet.dotx"
Case "6"
fn = "C:\QA\Templates\Core Earth Test Sheet.dotx"
Case "7"
fn = "C:\QA\Templates\Core Single Phase Power Cable.dotx"
Case "8"
fn = "C:\QA\Templates\Core Three Phase Power Cable.dotx"
Case "9"
fn = "C:\QA\Templates\Core Intrinsically Safe Cable.dotx"
Case Else
MsgBox "Your Report is not identified:" & "Please select the right Report"
End Select
' fn = Environ("SystemDrive") & "\QA\Templates\"
Set wApp = New Word.Application
' MsgBox "Directory:" & fn
Set wDoc = wApp.Documents.Open(fn)
With CurrentDb.OpenRecordset("qryReports")
Do While Not .EOF
wDoc.Bookmarks("Project").Range.Text = Nz(!Project, "")
' wDoc.Bookmarks("Location").Range.Text = Nz(!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(!Prefix, !Type)
wDoc.Bookmarks("Origin").Range.Text = Nz(!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(!Certification, "")
Path = "C:\QA\Project\Reports\"
fn = (Nz(!Prefix, "")) & "-" & (Nz(!Type, "")) & "-" & (Nz(!Cores, "")) & ".doc"
wDoc.SaveAs2 FileName:=Path & fn, FileFormat:=wdFormatDocument
If Err.Number = 0 Then
MsgBox "The file was saved as " & Path & fn, , "Saved"
Else
MsgBox "Error " & Err.Number & vbCr & Err.Description
End If
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(!Project, ""))
' wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(!Prefix, !Type))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(!DateChecked, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(!Certification, ""))
.MoveNext
Loop
.Close
End With
wDoc.Close True
wApp.Quit
Set wDoc = Nothing
Set wApp = Nothing
End Sub