T
Tom
Hi – small problem that has me stumped, hope somebody can offer some
advice.
I have a small database that collects field data. Included is a table
that stores a hyperlink to a Word document with pictures. Once a week
I need to print out all the records for the previous week including
the attachments, in order.
The code I use is below. The problem I am having is that the reports
and attachments get out of order. For example, I’ll get Report1,
Attachment1, Report2, Report3, Attachment2, etc… Then I have to go
back by hand and reorder everything – very tedious.
I don’t see any way the code below would cause this, so I’m assuming
that the issue in the time it takes the word document to open and
print, the code has moved on to the next record in rst and has printed
it already.
How do I force Access to wait till Word is done printing before moving
on? Or is my assumption wrong and there is a different problem.
Thanks
Tom
**************************
sqlstr = "Select InspectionID from tblInspection WHERE
InspectionDate" _
& " between #" & dtmStart & "# and #" & dtmEnd & "# Order
by InspectionDate"
Set rst = CurrentDb.OpenRecordset(sqlstr, dbOpenSnapshot)
Do Until rst.EOF
strWhere = "InspectionID =" & rst!InspectionID
DoCmd.OpenReport "rptInspection", , , strWhere
DoCmd.Close acReport, "rptinspection"
sqlstr = "Select AttachmentPath from tblAttachment where
inspectionid = " & rst!InspectionID
Set rst2 = CurrentDb.OpenRecordset(sqlstr, dbOpenSnapshot)
Do Until rst2.EOF
Select Case Right(rst2!AttachmentPath, 4)
Case Is = ".doc"
Set objDoc = objWord.Documents.Open("""" & rst2!
AttachmentPath & """", , , , , , , , , , , True)
objDoc.PrintOut
objDoc.Close
' case is = place holder for future support of other
document types
Case Else
MsgBox "Sorry - can't print the attachment associated
with Record " & rst!InspectionID & ": " & vbCrLf
& rst2!AttachmentPath
End Select
rst2.MoveNext
Loop
advice.
I have a small database that collects field data. Included is a table
that stores a hyperlink to a Word document with pictures. Once a week
I need to print out all the records for the previous week including
the attachments, in order.
The code I use is below. The problem I am having is that the reports
and attachments get out of order. For example, I’ll get Report1,
Attachment1, Report2, Report3, Attachment2, etc… Then I have to go
back by hand and reorder everything – very tedious.
I don’t see any way the code below would cause this, so I’m assuming
that the issue in the time it takes the word document to open and
print, the code has moved on to the next record in rst and has printed
it already.
How do I force Access to wait till Word is done printing before moving
on? Or is my assumption wrong and there is a different problem.
Thanks
Tom
**************************
sqlstr = "Select InspectionID from tblInspection WHERE
InspectionDate" _
& " between #" & dtmStart & "# and #" & dtmEnd & "# Order
by InspectionDate"
Set rst = CurrentDb.OpenRecordset(sqlstr, dbOpenSnapshot)
Do Until rst.EOF
strWhere = "InspectionID =" & rst!InspectionID
DoCmd.OpenReport "rptInspection", , , strWhere
DoCmd.Close acReport, "rptinspection"
sqlstr = "Select AttachmentPath from tblAttachment where
inspectionid = " & rst!InspectionID
Set rst2 = CurrentDb.OpenRecordset(sqlstr, dbOpenSnapshot)
Do Until rst2.EOF
Select Case Right(rst2!AttachmentPath, 4)
Case Is = ".doc"
Set objDoc = objWord.Documents.Open("""" & rst2!
AttachmentPath & """", , , , , , , , , , , True)
objDoc.PrintOut
objDoc.Close
' case is = place holder for future support of other
document types
Case Else
MsgBox "Sorry - can't print the attachment associated
with Record " & rst!InspectionID & ": " & vbCrLf
& rst2!AttachmentPath
End Select
rst2.MoveNext
Loop