Solved

Create, protect and mail report as word document

Posted on 2001-06-20
6
318 Views
Last Modified: 2008-02-01
This is what i want to do:

Create a report and e-mail it from Access - this i can do.  The problem is that this document must be protected as read only .

I have 2 options.

Option 1
Create and save the report in access and then open it through access with MS-word, set the protection by hand BUT then i need to mail the document from a stored location THIS I CAN'T DO !!!

Option 2
Create the report, set the protection property from access and then mail it.  CAN I SET THE PROTECTION FROM ACCESS?

Help urgently needed!

Thanx
0
Comment
Question by:Tryna
6 Comments
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6209843
Hi Tryna,

After you created a Word document Object in Access, try:
WordObj.WritePassword = "MyPass"
or
WordObj.Document.WritePassword = "MyPass"

Where WordObj is the reference to you Word Object.

I never tried it before, so please let me know if it works.

Hope this helps,

Nosterdamus
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6209856
To check if the method I suggested is working, you can test the value of WriteReserved:

Debug.print WordObj.WriteReserved  'Should display False
WordObj.WritePassword = "MyPass"
Debug.print WordObj.WriteReserved  'Should display True

Hope this helps,

Nosterdamus
0
 
LVL 6

Expert Comment

by:PsychoDazey
ID: 6210228
I dont know if this will work for sure, but have you tried doing a mail merge?  I believe you could create the template and password protect it.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Accepted Solution

by:
MB earned 150 total points
ID: 6210407
Tryna,  I know this will work from Access 97 as I've used it before.  It sends the document as an outlook attachment.

Option Compare Database
Option Explicit

    Private objWord As Word.Application
   
    Const FILE_SHARE_READ = &H1

    Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
   
Sub CreateInfractionDocument()
    On Error GoTo Proc_Err
   
    Dim strFileLoc  As String
   
    strFileLoc = "d:\lookat\temp\x.doc"
   
    Set objWord = New Word.Application
   
    objWord.Documents.Add
    objWord.ActiveDocument.SaveAs strFileLoc
    objWord.Quit
   
    SetFileAttributes strFileLoc, FILE_SHARE_READ
   
    SendEMailMsg False, "baderms@state.gov", "Subject Line", "", strFileLoc
   
Proc_Exit:
    Set objWord = Nothing
    Exit Sub

Proc_Err:
    MsgBox Err.Number & " - " & Err.Description
    Resume Proc_Exit
   
End Sub

Sub SendEMailMsg(DisplayMsg As Boolean, Receiver As String, Optional strSubject, Optional strCC, Optional AttachmentPath)
    On Error Resume Next
   
    Dim objOutlook          As Outlook.Application
    Dim objOutlookMsg       As Outlook.MailItem
    Dim objOutlookRecip     As Outlook.Recipient
    Dim objOutlookAttach    As Outlook.Attachment
    Dim CallDescription     As String
   
    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")
   
    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
   
    With objOutlookMsg
   
        ' Add the To recipient(s) to the message.
        Set objOutlookRecip = .Recipients.Add(Receiver)
        objOutlookRecip.Type = olTo
       
'        Add the CC recipient(s) to the message.
        If IsMissing(strCC) Then
            strCC = ""
        End If
       
        'If NoValue(strCC) = False Then
        '    Set objOutlookRecip = .Recipients.Add(strCC)
        '    objOutlookRecip.Type = olCC
        'End If
       
        ' Add the From recipient(s) to the message.
        'objOutlookMsg.SentOnBehalfOfName = GetSetting(App.EXEName, "Defaults", "EMailFrom")
       
        ' Set the Subject, Body, and Importance of the message.
        .Subject = strSubject
       
        .Importance = olImportanceHigh  'High importance
   
        'Request Deleivery Report
        'If GetSetting(App.EXEName, "Defaults", "EMailReceipt") = 1 Then
        '    .OriginatorDeliveryReportRequested = olTrackingDelivered
        'End If
       
        'Request Read Report
        'If GetSetting(App.EXEName, "Defaults", "EMailRead") = 1 Then
        '    .ReadReceiptRequested = olTrackingRead
        'End If
       
        ' Add attachments to the message.
        If IsMissing(AttachmentPath) Then
            AttachmentPath = ""
        End If
        'If NoValue(AttachmentPath) = False Then
            Set objOutlookAttach = .Attachments.Add(AttachmentPath)
        'End If
       
        ' Should we display the message before sending?
        If DisplayMsg Then
            .Display
        Else
            .Send
        End If
   
    End With

    Set objOutlook = Nothing
   
End Sub
0
 
LVL 2

Expert Comment

by:Charityg
ID: 6210626
OR instead of sending an rtf which is editable, you can send the report in snapshot format. The user must have the snapshot viewer installed to view the document, but I alway include a link to Microsoft's download site whenever I send a .snp file.

The sendObject command line looks like this

DoCmd.SendObject acSendReport, strdocname, "SnapShot Format", , , , , Chr(13) & "To view this document you must install SnapShot Viewer which can be downloaded from:" & Chr(13) & Chr(13) & "http://www.microsoft.com/accessdev/prodinfo/snapdl.htm"

The last line includes the site for download. This method is extremely EASY and once you install it, you're pretty much set.

Hope this helps you
0
 

Author Comment

by:Tryna
ID: 6227351
MB

Your solution put me on the right track although it's not exactly what i need to do.  Your solution sets the property to read only which means that the mail recipient can still open and change the document but then must save it under a different name.

To clarify, the document that i'm trying to create and mail is a type of certifcate for laboratory results.  The recipient may under no circumstance change any of the information contained in the document.  In other words, i need to set the property that you find in MS word under:

Tools > Protect Document - The protect document form appears where you can protect it for Tracked Changes, Comments of Forms.  I need to do protection for Forms with a password.

As a first time user of any form of variables of type OBJECT, it took me a while to figure out that there is something like "References" to be set in the tools menu to be able to access the other Microsoft applications for Automation.  Luckily i'm a fast learner. Below is the code you provided followed by the code as i changed it.

   objWord.Documents.Add
   objWord.ActiveDocument.SaveAs strFileLoc
   objWord.Quit
   
I changed it as follows :

   objWord.Documents.Open "c:\test\test.doc"
   objWord.ActiveDocument.Protect wdAllowOnlyFormFields
   objWord.ActiveDocument.Save
   objWord.Quit

If there is another (easier) way or ideas on how to add a password to the document, i would like to know about it BUT for posting the closest thing to a solution (i.e. 99.9%) The points  - with compliments !!!
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now