Link to home
Start Free TrialLog in
Avatar of Sheils
SheilsFlag 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

Avatar of Rgonzo1971
Rgonzo1971

Hi,

Place

Const olMaximized = 0

at the beginnning of your code

Regards
Avatar of 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
maybe because you set the OL obj as nothing at the end of the code
Avatar of 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
Avatar of Sheils
Sheils
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sheils

ASKER

I found the code required to make it work