The workgroup extensions for Word messaging functions require that a Mail session is established before they are used. A Mail session validates the identity of the user and indicates which message store to use when finding and saving messages.
Because the current version of WordBasic does not support global variables, a Mail session cannot remain open when a macro completes execution. To open and close a Mail session, include both MAPILogon and MAPILogoff in every macro that uses the workgroup extensions.
Subroutines and functions can use the Mail session established by a calling procedure or function if you pass the Mail session handle to the subroutine or function. The following example passes the session handle from the main subroutine to the DisplayOriginator subroutine:
Sub MAIN Session = MAPILogon(0, "", "", 0, 0) DisplayOriginator Session result = MAPILogoff(Session, 0, 0, 0) End Sub Sub DisplayOriginator(MainSession) Dim MessageID$, Originator$, Address$ result = MAPIFindNext(MainSession, 0, "", "", 0, 0, MessageID$) result = MAPIReadMail(MainSession, 0, MessageID$, 0, 0) result = MAPIQueryOriginator(Originator$, Address$) MsgBox Originator$ + " @ " + Address$ End Sub