MITSupport
Registered User.
- Local time
- Today, 19:12
- Joined
- Aug 8, 2016
- Messages
- 46
Hi all
I am having issues with some coding and i was wondering if i am doing it right.
Here is a copy of the code that i am doing:
I am wondering if i am doing this right or if there is an easier way to get the information from this particular query to the different word templates.
Please help. TIA
Allan
I am having issues with some coding and i was wondering if i am doing it right.
Here is a copy of the code that i am doing:
Code:
Public Sub ExportToWord()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rsReports As DAO.Recordset
Set wApp = New Word.Application
Set rsReports = CurrentDb.OpenRecordset("qryReports")
If Me.txtReportType = "Power" Then
Set wDoc = wApp.Documents.Open("C:\QA\Templates\Core Power Cable.dotx")
If Not rsReports.EOF Then rsReports.MoveFirst
Do Until rsReports.EOF
wDoc.Bookmarks("Project").Range.Text = Nz(rsReports!Project, "")
wDoc.Bookmarks("Location").Range.Text = Nz(rsReports!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, "")
wDoc.Bookmarks("Origin").Range.Text = Nz(rsReports!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(rsReports!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rsReports!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(rsReports!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(rsReports!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(rsReports!Certification, "")
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(rsReports!Project, ""))
wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(rsReports!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, ""))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(rsReports!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(rsReports!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(rsReports!Date, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(rsReports!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(rsReports!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(rsReports!Certification, ""))
rsReports.MoveNext
Loop
If Me.txtReportType = "Control" Then
Set wDoc = wApp.Documents.Open("C:\QA\Templates\Core COntrol Cable.dotx")
If Not rsReports.EOF Then rsReports.MoveFirst
Do Until rsReports.EOF
wDoc.Bookmarks("Project").Range.Text = Nz(rsReports!Project, "")
wDoc.Bookmarks("Location").Range.Text = Nz(rsReports!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, "")
wDoc.Bookmarks("Origin").Range.Text = Nz(rsReports!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(rsReports!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rsReports!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(rsReports!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(rsReports!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(rsReports!Certification, "")
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(rsReports!Project, ""))
wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(rsReports!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, ""))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(rsReports!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(rsReports!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(rsReports!Date, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(rsReports!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(rsReports!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(rsReports!Certification, ""))
rsReports.MoveNext
Loop
If Me.txtReportType = "Earth" Then
Set wDoc = wApp.Documents.Open("C:\QA\Templates\Core Earth Test Sheet.dotx")
If Not rsReports.EOF Then rsReports.MoveFirst
Do Until rsReports.EOF
wDoc.Bookmarks("Project").Range.Text = Nz(rsReports!Project, "")
wDoc.Bookmarks("Location").Range.Text = Nz(rsReports!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, "")
wDoc.Bookmarks("Origin").Range.Text = Nz(rsReports!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(rsReports!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rsReports!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(rsReports!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(rsReports!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(rsReports!Certification, "")
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(rsReports!Project, ""))
wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(rsReports!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, ""))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(rsReports!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(rsReports!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(rsReports!Date, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(rsReports!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(rsReports!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(rsReports!Certification, ""))
rsReports.MoveNext
Loop
If Me.txtReportType = "Motor" Then
Set wDoc = wApp.Documents.Open("C:\QA\Templates\Core Test Motor Test Sheet.dotx")
If Not rsReports.EOF Then rsReports.MoveFirst
Do Until rsReports.EOF
wDoc.Bookmarks("Project").Range.Text = Nz(rsReports!Project, "")
wDoc.Bookmarks("Location").Range.Text = Nz(rsReports!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, "")
wDoc.Bookmarks("Origin").Range.Text = Nz(rsReports!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(rsReports!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rsReports!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(rsReports!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(rsReports!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(rsReports!Certification, "")
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(rsReports!Project, ""))
wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(rsReports!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, ""))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(rsReports!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(rsReports!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(rsReports!Date, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(rsReports!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(rsReports!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(rsReports!Certification, ""))
rsReports.MoveNext
Loop
If Me.txtReportType = "Instrument" Then
Set wDoc = wApp.Documents.Open("C:\QA\Templates\Core Instrument Test Sheet.dotx")
If Not rsReports.EOF Then rsReports.MoveFirst
Do Until rsReports.EOF
wDoc.Bookmarks("Project").Range.Text = Nz(rsReports!Project, "")
wDoc.Bookmarks("Location").Range.Text = Nz(rsReports!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, "")
wDoc.Bookmarks("Origin").Range.Text = Nz(rsReports!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(rsReports!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rsReports!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(rsReports!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(rsReports!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(rsReports!Certification, "")
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(rsReports!Project, ""))
wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(rsReports!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, ""))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(rsReports!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(rsReports!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(rsReports!Date, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(rsReports!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(rsReports!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(rsReports!Certification, ""))
rsReports.MoveNext
Loop
If Me.txtReportType = "ITP" Then
Set wDoc = wApp.Documents.Open("C:\QA\Templates\Core Earth Test Sheet.dotx")
If Not rsReports.EOF Then rsReports.MoveFirst
Do Until rsReports.EOF
wDoc.Bookmarks("Project").Range.Text = Nz(rsReports!Project, "")
wDoc.Bookmarks("Location").Range.Text = Nz(rsReports!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, "")
wDoc.Bookmarks("Origin").Range.Text = Nz(rsReports!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(rsReports!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rsReports!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(rsReports!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(rsReports!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(rsReports!Certification, "")
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(rsReports!Project, ""))
wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(rsReports!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, ""))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(rsReports!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(rsReports!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(rsReports!Date, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(rsReports!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(rsReports!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(rsReports!Certification, ""))
rsReports.MoveNext
Loop
If Me.txtReportType = "Single Phase" Then
Set wDoc = wApp.Documents.Open("C:\QA\Templates\Core Single Phase Power Cable.dotx")
If Not rsReports.EOF Then rsReports.MoveFirst
Do Until rsReports.EOF
wDoc.Bookmarks("Project").Range.Text = Nz(rsReports!Project, "")
wDoc.Bookmarks("Location").Range.Text = Nz(rsReports!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, "")
wDoc.Bookmarks("Origin").Range.Text = Nz(rsReports!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(rsReports!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rsReports!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(rsReports!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(rsReports!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(rsReports!Certification, "")
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(rsReports!Project, ""))
wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(rsReports!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, ""))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(rsReports!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(rsReports!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(rsReports!Date, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(rsReports!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(rsReports!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(rsReports!Certification, ""))
rsReports.MoveNext
Loop
If Me.txtReportType = "Three Phase" Then
Set wDoc = wApp.Documents.Open("C:\QA\Templates\Core Three Phase Power Cable.dotx")
If Not rsReports.EOF Then rsReports.MoveFirst
Do Until rsReports.EOF
wDoc.Bookmarks("Project").Range.Text = Nz(rsReports!Project, "")
wDoc.Bookmarks("Location").Range.Text = Nz(rsReports!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, "")
wDoc.Bookmarks("Origin").Range.Text = Nz(rsReports!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(rsReports!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rsReports!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(rsReports!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(rsReports!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(rsReports!Certification, "")
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(rsReports!Project, ""))
wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(rsReports!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, ""))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(rsReports!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(rsReports!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(rsReports!Date, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(rsReports!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(rsReports!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(rsReports!Certification, ""))
rsReports.MoveNext
Loop
If Me.txtReportType = "IS" Then
Set wDoc = wApp.Documents.Open("C:\QA\Templates\Core Intrinsically Safe Cable.dotx")
If Not rsReports.EOF Then rsReports.MoveFirst
Do Until rsReports.EOF
wDoc.Bookmarks("Project").Range.Text = Nz(rsReports!Project, "")
wDoc.Bookmarks("Location").Range.Text = Nz(rsReports!Location, "")
wDoc.Bookmarks("CableNumber").Range.Text = Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, "")
wDoc.Bookmarks("Origin").Range.Text = Nz(rsReports!OriginZone, "")
wDoc.Bookmarks("Dest").Range.Text = Nz(rsReports!DestinationZone, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rsReports!DateChecked, "")
wDoc.Bookmarks("CheckedBy").Range.Text = Nz(rsReports!CheckedBy, "")
wDoc.Bookmarks("Comments").Range.Text = Nz(rsReports!Comments, "")
wDoc.Bookmarks("Tool").Range.Text = Nz(rsReports!Certification, "")
wDoc.Bookmarks("Project").Range.Delete wdCharacter, Len(Nz(rsReports!Project, ""))
wDoc.Bookmarks("Location").Range.Delete wdCharacter, Len(Nz(rsReports!Location, ""))
wDoc.Bookmarks("CableNumber").Range.Delete wdCharacter, Len(Nz(rsReports!CableType, rsReports!Prefix, rsReports!Type, ""))
wDoc.Bookmarks("Origin").Range.Delete wdCharacter, Len(Nz(rsReports!OriginZone, ""))
wDoc.Bookmarks("Dest").Range.Delete wdCharacter, Len(Nz(rsReports!DestinationZone, ""))
wDoc.Bookmarks("Date").Range.Delete wdCharacter, Len(Nz(rsReports!Date, ""))
wDoc.Bookmarks("CheckedBy").Range.Delete wdCharacter, Len(Nz(rsReports!CheckedBy, ""))
wDoc.Bookmarks("Comments").Range.Delete wdCharacter, Len(Nz(rsReports!Comments, ""))
wDoc.Bookmarks("Tool").Range.Delete wdCharacter, Len(Nz(rsReports!Certification, ""))
rsReports.MoveNext
Loop
wDoc.Close False
wApp.Quit
Set wDoc = Nothing
Set wApp = Nothing
Set rsReports = Nothing
I am wondering if i am doing this right or if there is an easier way to get the information from this particular query to the different word templates.
Please help. TIA
Allan