UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Attaching And Sending A .docx Or .rtf File Through Access Automation, Access 2016    
 
   
ashbee
post Feb 1 2020, 09:02 AM
Post#1



Posts: 8
Joined: 14-December 19



Hello

I'm hoping to get some guidance on which command would best suit what I'm trying to do. I have a word form with lots of formatting that I populate with data from Access. I've managed to get it set up so I can click a command button on an individual record to generate a word file using bookmarks that is then saved using the primary key on my Access record. All good so far, what I'm now stuck on is how to open the Outlook window with the email address already filled in from them email field on my form with the word document attached so that I can add my message and press send when I'm ready.

I can do this with a PDF report no problem but what I'm struggling with is that the word file sits in a folder outside of Access so modifying my PDF report code isn't working.

Here is the code that generates the word file:

CODE
Private Sub cmdwordgenerate_Click()
    Dim oWd  As Object 'Word.Application
    Dim oDoc As Object 'Word.Document
    Dim bm   As Object 'Word.Bookmark
    
    'Set oWd = New Word.Application
    Set oWd = CreateObject("Word.Application")
    Set oDoc = oWd.Documents.Open("C:\Users\Letters\MyForm.docx")
    
    Set bm = oDoc.Bookmarks("txtmodule")
    bm.Range.Text = Nz(OFFSET_NAME, "")
    oDoc.saveas2 CurrentProject.Path & "\" & OFFSET_NAME & " Requirements.docx"
    oWd.Visible = True
    oWd.Quit
End Sub


I thought about writing code that will generate the file (as above) and add code to save the file path to a field in my access database. Then a second command button where I could refer to the path, e.g:

CODE
strPath = "C:\Users\Letters\MyForm" & [OFFSET_NAME]
strFilter = ".docx"
strFile = (strPath & strFilter)
.Attachments.Add (strFile)


Is this the best way to try to achieve the end goal of opening an outlook message window that is pre-populated with my field email address and the file already attached - or is there a better way? I feel like I'm missing something very obvious. I've checked my form and it doesn't make any difference to its functionality if it is saved as a .docx or .rtf file and it's looking like .rtf might make working out the code easier...
Go to the top of the page
 
ashbee
post Feb 1 2020, 05:52 PM
Post#2



Posts: 8
Joined: 14-December 19



I've figured it out I think - just need to test it thoroughly in the morning then will post the code here for others to refer to.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    5th April 2020 - 12:37 AM