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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting a .jpg picture into a .rft file using vba?

Status
Not open for further replies.

Lamprey79

Programmer
Mar 30, 2005
9
US
I'm outputting an access report to .rtf (for attachment to an automatic email), but the problem is that an .jpg embedded in the report doesn't make it into the word file. Is there a way to modify my code to make it export with the rest of the report?

Perhaps it's possible to insert the .jpg into the .rtf later using VBA?

==========================================================

Here's my code:

Private Sub Objective_DblClick(Cancel As Integer)

Dim dbs As Database
Dim rst As Object
Dim qry As QueryDef
Dim CallID As Long
Dim strDocName, strOutputPath, strOutputFile As String
Dim OPenView As Boolean

Set dbs = CurrentDb

For Each qdf In dbs.QueryDefs
If qdf.Name = "qryCallDetail" Then DoCmd.DeleteObject acQuery, "qryCallDetail"
Next qdf

CallID = Me.CallID

Set qry = dbs.CreateQueryDef("qryCallDetail", "SELECT tblCallers.CallerName, tblCallers.Phone1, tblCallers.Phone2, tblCallers.Email, tblConsultants.ConsultantName, tblProduct.ProductName, tblCall.CallID, tblCall.Client, tblCall.Date, tblCall.Location, tblCall.ConsultantAttendee1, tblCall.ConsultantAttendee2, tblCall.ConsultantAttendee3, tblCall.ConsultantAttendee4, tblCall.ConsultantAttendee5, tblCall.ClientAttendee1, tblCall.ClientAttendee2, tblCall.ClientAttendee3, tblCall.ClientAttendee4, tblCall.ClientAttendee5, tblCall.Objective, tblCall.Overview, tblCall.Topics, tblCall.Status, tblCall.FollowUp " & _
"FROM ((tblCallers INNER JOIN tblConsultants ON tblCallers.CallerID = tblConsultants.CallerID) INNER JOIN tblProduct ON tblConsultants.ConsultantsID = tblProduct.ConsultantsID) INNER JOIN tblCall ON tblProduct.ProductID = tblCall.ProductID " & _
"WHERE (((tblCall.CallID)=" & CallID & "));")

strDocName = "rptMeetingDetail"
DoCmd.OpenReport strDocName, acPreview, , strWhere

strOutputFile = "test.rtf" 'this will get changed later to give a unique file name base on date/time
strOutputPath = "\\Ncateav4\cavol4\PTRUST\Communications\MGrabowski\" & strOutputFile
OPenView = False

DoCmd.OutputTo acReport, strDocName, acFormatRTF, strOutputPath, OPenView

End Sub
 
Word exposes a rich object model and can be used to add a picture rather easily through automation. The tricky part will be positioning it where you want it.

Here's an example that may help you get started:
Code:
Public Function InsertJPG(ByVal strDoc As String, ByVal strPic As String) As Boolean
On Error GoTo ErrHandler
  Dim wd As New Word.Application
  Dim doc As Word.Document
  Dim shp As Word.Shape
  
  Set doc = wd.Documents.Open(strDoc, , , False)
  Set shp = doc.Shapes.AddPicture(strPic, False, True, 50, 200, 50, 50)
  With shp
    .ScaleHeight 1, msoTrue
    .ScaleWidth 1, msoTrue
  End With
  doc.Save

  InsertJPG = True
ExitHere:
  On Error Resume Next
  wd.Quit
  Set doc = Nothing
  Set wd = Nothing
  Exit Function
ErrHandler:
  Debug.Print Err, Err.Description
  Resume ExitHere
End Function

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top