[AccessD] First run creating Outlook mail item does not foreground itself?

Ryan W wrwehler at gmail.com
Tue Jan 24 10:56:17 CST 2023


As the subject states:

When I run code to compose an email and display the email, the email window
stays grouped but minimized or hidden on the first run.

Subsequent runs, the created email is foregrounded?

If I close outlook and re-open it, the process starts again where the first
composition stays hidden until I go manually foreground it.

code:

Public Sub CreateEmail(subj As String, Optional body As String, Optional
ToWho As Variant, Optional CCWho As Variant, Optional attachment As Variant
= Null)
    On Error GoTo CreateEmail_Error

    Dim oLook As Object, oMail As Object, origBody As String

    On Error Resume Next
    Set oLook = GetObject(, "Outlook.Application")
    If Err.number <> 0 Then
        Set oLook = CreateObject("Outlook.Application")
    End If
    Err.Clear
    On Error GoTo CreateEmail_Error
    Set oMail = oLook.CreateItem(0)
    With oMail
        .Display
        If Not (IsMissing(ToWho) Or IsNull(ToWho)) Then .To = ToWho
        If Not (IsMissing(CCWho) Or IsNull(CCWho)) Then .cc = CCWho
        .Subject = subj
        .BodyFormat = 2 'html
        .body = body
        If Not IsNull(attachment) Then
            .Attachments.Add attachment
        End If
    End With

CreateEmail_Exit:
    On Error Resume Next
    Set oMail = Nothing
    Set oLook = Nothing
    Exit Sub

CreateEmail_Error:

    MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure
CreateEmail."
    Resume CreateEmail_Exit
End Sub


IIRC .Display should show the email composition window.


Any ideas?


More information about the AccessD mailing list