How it Works

Distributing a Section

Sections are actually stored as Word subdocuments. The following are the key bits of code to distribute a section.

Open the subdocument


    ViewMasterDocument
    OpenSubdocument
    ScreenRefresh

Store the owner name and address in the subdocument (this is used to know where to return the document later)


    EditGoTo "\headinglevel"
    CharLeft
    LineDown 1, 1
    ReportTitle$ = Selection$()
    result = Constants.fCurrentUser(OwnerName$, OwnerAddress$)
    result = SetDocumentVar("OwnerName", OwnerName$)
    result = SetDocumentVar("OwnerAddress", OwnerAddress$)
    result = SetDocumentVar("ReportTitle", ReportTitle$)    

Send the document via calls to MAPISetAttachment and MAPISendMail


If SendMailDialog(ReportTitle$, FName$) = - 1 Then

Function SendMailDialog(Subject$, Attachment$)
    MAPI_LOGON_UI = 1
    MAPI_DIALOG = 8
    Session = MAPILogon(0, "", "", MAPI_LOGON_UI, 0)
    result = MAPISetAttachment("", Attachment$, - 1, 0, 0)
    result = MAPISendMail(Session, 0, Subject$, \
        "Please complete this report.", MAPI_DIALOG, 0)
    SendMailDialog = result
    result = MAPILogoff(Session, 0, 0, 0)
End Function

Returning a Section

Returning a section involves automatically determining where to send it from entries in document variables. The following are the key bits of code to return a section.

Get Address to return to


        OwnerName$ = GetDocumentVar$("OwnerName")
        OwnerAddress$ = GetDocumentVar$("OwnerAddress")

Log on to MAPI


        Session = MAPILogon(0, "", "", MAPI_LOGON_UI, 0)

Set the recipient and attachment


        result = MAPISetRecipient(1, OwnerName$, OwnerAddress$)
        result = MAPISetMessageType(MessageType$)
        result = MAPISetAttachment("", fName$, - 1, 0, 0)

Call MAPISendMail to send the document


        result = MAPISendMail(session, 0, Subject$, "", 0, 0)
        If result >= 0 Then
            MsgBox "Section sent to " + Ownername$ + ".", 64
        End If

Log off MAPI


        result = MAPILogoff(Session, 0, 0, 0)