Avatar of Sheils
Sheils
Flag for Australia asked on

How to set ActiveWindow.WindowState = olMaximized in late binding

I am trying to open outlook from msaccess using late binding. I want to display the mail message before sending. The code works but when I click send the message stays in the inbox until I manually open the outlook application.

Using objOutlook.ActiveWindow.WindowState = olMaximized in early binding solves this problem but it does not work in late binding.

What I'm I missing. Below is a snippet of my code:

Dim objOutlookApp  As Object
    Dim objOutlookMail As Object
      
    On Error Resume Next

    Set objOutlookApp = GetObject(, "Outlook.Application")
    
        If Err.Number = 429 Then
            Err.Clear
            
            Set objOutlookApp = CreateObject("Outlook.Application")
        End If

	On Error GoTo 0

    Set objOutlookMail = objOutlookApp.CreateItem(olMailItem)   
   
    With objOutlookMail
    .To = "email@email.com"
    .Body = "this is a test2"
    .Display
    
    End With
	
	objOutlookApp.ActiveWindow.WindowState = olMaximized

Open in new window

OutlookMicrosoft Access

Avatar of undefined
Last Comment
Sheils

8/22/2022 - Mon
Rgonzo1971

Hi,

Place

Const olMaximized = 0

at the beginnning of your code

Regards
Sheils

ASKER
I actually do have that:

Option Compare Database

Option Explicit

Const olMailItem As Long = 0
Const olAppointmentItem As Long = 1
Const olContactItem As Long = 2
Const olTaskItem As Long = 3
Const olMaximized = 0
Const olMinimized = 1
Const olNormalWindow = 2

Public Function openOutlook()


    Dim objOutlookApp  As Object 'Comment out when testing early binding
    Dim strOutLookMsg As String
    Dim objOutlookMail As Object

Open in new window


It does not help
Rgonzo1971

maybe because you set the OL obj as nothing at the end of the code
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Sheils

ASKER
no it's not set to nothing. I works find when I use early binding. But don't work with late binding. This means that there is an additional object that I need to declare and set I just don't know which one.
ASKER CERTIFIED SOLUTION
Sheils

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Sheils

ASKER
I found the code required to make it work