[AccessD] First run creating Outlook mail item does not foreground itself?
Arthur Fuller
fuller.artful at gmail.com
Thu Jan 26 11:54:53 CST 2023
I tried your code and got nowhere, so at least you're ahead of me. I built
a test harness and passed all the parameters:
<code>
Function TestHarness()
On Error Resume Next
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure TestHarness, line " & Erl & "."
Exit Function
End If
On Error GoTo 0
Dim strSubj As String, strBody As String
Dim varTo As Variant, varCC As Variant, varAttach As Variant
strSubj = "How's the weather in California?"
strBody = "I hope everything is ok with you."
varTo = "fuller.artful at gmail.com"
varCC = "jwcolby at gmail.com"
varAttach = "C:\apps\c\hello.c"
CreateEmail(strSubj, _
strBody, _
varTo, _
varCC, _
varAttach)
End Function
</code>
The whole call to CreateMail is flagged as an error. I don't see where I
went wrong. Can you see my mistake?
On Tue, Jan 24, 2023 at 1:37 PM Ryan W <wrwehler at gmail.com> wrote:
> Bill,
> Thanks but neither of those worked.
>
> I did find instances where if outlook was displaying the email as one
> would expect, next time around (with enough idle time for outlook or some
> other event) it will cease to foreground the composition window
> occasionally.
>
>
>
> On Tue, Jan 24, 2023 at 12:19 PM Bill Benson <bensonforums at gmail.com>
> wrote:
>
> > “,” was typo, meant “.”
> >
> > On Tue, Jan 24, 2023 at 1:18 PM Bill Benson <bensonforums at gmail.com>
> > wrote:
> >
> > > Try adding oMail,GetInspector.Activate or
> oLook.ActiveInspector.Activate
> > > after .Display
> > >
> > > On Tue, Jan 24, 2023 at 11:56 AM Ryan W <wrwehler at gmail.com> wrote:
> > >
> > >> 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?
> > >> --
> > >> AccessD mailing list
> > >> AccessD at databaseadvisors.com
> > >> https://databaseadvisors.com/mailman/listinfo/accessd
> > >> Website: http://www.databaseadvisors.com
> > >>
> > >
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > https://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
--
Arthur
More information about the AccessD
mailing list