Late binding for OLE Automation to Outlook.

R

ReidarT

I have an application that uses OLE automation from Acess to Word and
Outlook.
I want to use late binding because of different versions of Word and
Outlook.

I use late binding for Word, and it works OK, but I haven't managed to do it
with Outlook.

I need: From, To, Subject and Attachment

Dim olkApp as Object
Set olkApp = CreateObject("Outlook.Application")
' from here I am confused
Dim omMail As Object
Dim olMailItem As Object
'Code stops here
Set omMail = olkApp.CreateItem(omMail(olMailItem))

Best regards
ReidarT
 
R

ReidarT

Here is the beginning of the code :
Private Sub HENInfo_Click()
Dim olkApp As Object
'Dim olkApp As Outlook.Application
Dim omMail As Object
Dim olMailItem As Object

If Me.epost <> "" Then
'On Error GoTo Hotelinfo_Err
Set olkApp = CreateObject("Outlook.Application")
'Here is the stop of the code
Set omMail = olkApp.CreateItem(olMailItem)
omMail.To = Forms!Grunndata_Frm!epost
omMail.Subject = "Information from sender."

best regards
Reidart
 
G

Graham Mandeno

Hi Reidar

Sorry if this is a silly question, but have you declared the Outlook
constants you are using (for example, olMailItem)? If you have removed the
reference for late binding then you will need to do so.
 
T

TC

That's my bet!

TC


Graham Mandeno said:
Hi Reidar

Sorry if this is a silly question, but have you declared the Outlook
constants you are using (for example, olMailItem)? If you have removed the
reference for late binding then you will need to do so.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

ReidarT said:
Here is the beginning of the code :
Private Sub HENInfo_Click()
Dim olkApp As Object
'Dim olkApp As Outlook.Application
Dim omMail As Object
Dim olMailItem As Object

If Me.epost <> "" Then
'On Error GoTo Hotelinfo_Err
Set olkApp = CreateObject("Outlook.Application")
'Here is the stop of the code
Set omMail = olkApp.CreateItem(olMailItem)
omMail.To = Forms!Grunndata_Frm!epost
omMail.Subject = "Information from sender."

best regards
Reidart

to
do
 
R

reidarT

It is not a silly question.
When I used early binding by referencing Outlook Lib. obj
in references I had
Dim omMail as MailItem, and
Set omMail = olkApp.CreateItem(olMailItem)
now I use
Dim omMail As Object
Dim olMailItem As Object
and I think here is where i NEED HELP

best regards
ReidarT
-----Opprinnelig melding-----
Hi Reidar

Sorry if this is a silly question, but have you declared the Outlook
constants you are using (for example, olMailItem)? If you have removed the
reference for late binding then you will need to do so.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

ReidarT said:
Here is the beginning of the code :
Private Sub HENInfo_Click()
Dim olkApp As Object
'Dim olkApp As Outlook.Application
Dim omMail As Object
Dim olMailItem As Object

If Me.epost <> "" Then
'On Error GoTo Hotelinfo_Err
Set olkApp = CreateObject("Outlook.Application")
'Here is the stop of the code
Set omMail = olkApp.CreateItem(olMailItem)
omMail.To = Forms!Grunndata_Frm!epost
omMail.Subject = "Information from sender."

best regards
Reidart

"Cheryl Fischer" <[email protected]> skrev i melding
haven't managed to
do


.
 
G

Graham Mandeno

Aha! Therein lies the problem. You have a variable declared As Object, and
you are referring to it without setting its reference, so you will be
getting Error 91 (Object variable or With block variable not set).

olMailItem should actually be declared as a constant with the value 0.

I have included below a module which declares all the constants defined in
the Outlook 10 object library.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start module ============
Option Explicit

#Const EarlyBinding = 0
#If Not EarlyBinding Then

Public Enum OlActionCopyLike
olReply = 0 ' &h0
olReplyAll = 1 ' &h1
olForward = 2 ' &h2
olReplyFolder = 3 ' &h3
olRespond = 4 ' &h4
End Enum

Public Enum OlActionReplyStyle
olOmitOriginalText = 0 ' &h0
olEmbedOriginalItem = 1 ' &h1
olIncludeOriginalText = 2 ' &h2
olIndentOriginalText = 3 ' &h3
olLinkOriginalItem = 4 ' &h4
olUserPreference = 5 ' &h5
olReplyTickOriginalText = 1000 ' &h3E8
End Enum

Public Enum OlActionResponseStyle
olOpen = 0 ' &h0
olSend = 1 ' &h1
olPrompt = 2 ' &h2
End Enum

Public Enum OlActionShowOn
olDontShow = 0 ' &h0
olMenu = 1 ' &h1
olMenuAndToolbar = 2 ' &h2
End Enum

Public Enum OlAttachmentType
olByValue = 1 ' &h1
olByReference = 4 ' &h4
olEmbeddeditem = 5 ' &h5
olOLE = 6 ' &h6
End Enum

Public Enum OlBusyStatus
olFree = 0 ' &h0
olTentative = 1 ' &h1
olBusy = 2 ' &h2
olOutOfOffice = 3 ' &h3
End Enum

Public Enum OlDaysOfWeek
olSunday = 1 ' &h1
olMonday = 2 ' &h2
olTuesday = 4 ' &h4
olWednesday = 8 ' &h8
olThursday = 16 ' &h10
olFriday = 32 ' &h20
olSaturday = 64 ' &h40
End Enum

Public Enum OlDefaultFolders
olFolderDeletedItems = 3 ' &h3
olFolderOutbox = 4 ' &h4
olFolderSentMail = 5 ' &h5
olFolderInbox = 6 ' &h6
olFolderCalendar = 9 ' &h9
olFolderContacts = 10 ' &hA
olFolderJournal = 11 ' &hB
olFolderNotes = 12 ' &hC
olFolderTasks = 13 ' &hD
olFolderDrafts = 16 ' &h10
olPublicFoldersAllPublicFolders = 18 ' &h12
End Enum

Public Enum OlDisplayType
olUser = 0 ' &h0
olDistList = 1 ' &h1
olForum = 2 ' &h2
olAgent = 3 ' &h3
olOrganization = 4 ' &h4
olPrivateDistList = 5 ' &h5
olRemoteUser = 6 ' &h6
End Enum

Public Enum OlEditorType
olEditorText = 1 ' &h1
olEditorHTML = 2 ' &h2
olEditorRTF = 3 ' &h3
olEditorWord = 4 ' &h4
End Enum

Public Enum OlFlagStatus
olNoFlag = 0 ' &h0
olFlagComplete = 1 ' &h1
olFlagMarked = 2 ' &h2
End Enum

Public Enum OlFolderDisplayMode
olFolderDisplayNormal = 0 ' &h0
olFolderDisplayFolderOnly = 1 ' &h1
olFolderDisplayNoNavigation = 2 ' &h2
End Enum

Public Enum OlFormRegistry
olDefaultRegistry = 0 ' &h0
olPersonalRegistry = 2 ' &h2
olFolderRegistry = 3 ' &h3
olOrganizationRegistry = 4 ' &h4
End Enum

Public Enum OlGender
olUnspecified = 0 ' &h0
olFemale = 1 ' &h1
olMale = 2 ' &h2
End Enum

Public Enum OlImportance
olImportanceLow = 0 ' &h0
olImportanceNormal = 1 ' &h1
olImportanceHigh = 2 ' &h2
End Enum

Public Enum OlInspectorClose
olSave = 0 ' &h0
olDiscard = 1 ' &h1
olPromptForSave = 2 ' &h2
End Enum

Public Enum OlItemType
olMailItem = 0 ' &h0
olAppointmentItem = 1 ' &h1
olContactItem = 2 ' &h2
olTaskItem = 3 ' &h3
olJournalItem = 4 ' &h4
olNoteItem = 5 ' &h5
olPostItem = 6 ' &h6
olDistributionListItem = 7 ' &h7
End Enum

Public Enum OlJournalRecipientType
olAssociatedContact = 1 ' &h1
End Enum

Public Enum OlMailingAddress
olNone = 0 ' &h0
olHome = 1 ' &h1
olBusiness = 2 ' &h2
olOther = 3 ' &h3
End Enum

Public Enum OlMailRecipientType
olOriginator = 0 ' &h0
olTo = 1 ' &h1
olCC = 2 ' &h2
olBCC = 3 ' &h3
End Enum

Public Enum OlMeetingRecipientType
olOrganizer = 0 ' &h0
olRequired = 1 ' &h1
olOptional = 2 ' &h2
olResource = 3 ' &h3
End Enum

Public Enum OlMeetingResponse
olMeetingTentative = 2 ' &h2
olMeetingAccepted = 3 ' &h3
olMeetingDeclined = 4 ' &h4
End Enum

Public Enum OlMeetingStatus
olNonMeeting = 0 ' &h0
olMeeting = 1 ' &h1
olMeetingReceived = 3 ' &h3
olMeetingCanceled = 5 ' &h5
End Enum

Public Enum OlNetMeetingType
olNetMeeting = 0 ' &h0
olNetShow = 1 ' &h1
olExchangeConferencing = 2 ' &h2
End Enum

Public Enum OlNoteColor
olBlue = 0 ' &h0
olGreen = 1 ' &h1
olPink = 2 ' &h2
olYellow = 3 ' &h3
olWhite = 4 ' &h4
End Enum

Public Enum OlObjectClass
olApplication = 0 ' &h0
olNamespace = 1 ' &h1
olFolder = 2 ' &h2
olRecipient = 4 ' &h4
olAttachment = 5 ' &h5
olAddressList = 7 ' &h7
olAddressEntry = 8 ' &h8
olFolders = 15 ' &hF
olItems = 16 ' &h10
olRecipients = 17 ' &h11
olAttachments = 18 ' &h12
olAddressLists = 20 ' &h14
olAddressEntries = 21 ' &h15
olAppointment = 26 ' &h1A
olMeetingRequest = 53 ' &h35
olMeetingCancellation = 54 ' &h36
olMeetingResponseNegative = 55 ' &h37
olMeetingResponsePositive = 56 ' &h38
olMeetingResponseTentative = 57 ' &h39
olRecurrencePattern = 28 ' &h1C
olExceptions = 29 ' &h1D
olException = 30 ' &h1E
olAction = 32 ' &h20
olActions = 33 ' &h21
olExplorer = 34 ' &h22
olInspector = 35 ' &h23
olPages = 36 ' &h24
olFormDescription = 37 ' &h25
olUserProperties = 38 ' &h26
olUserProperty = 39 ' &h27
olContact = 40 ' &h28
olDocument = 41 ' &h29
olJournal = 42 ' &h2A
olMail = 43 ' &h2B
olNote = 44 ' &h2C
olPost = 45 ' &h2D
olReport = 46 ' &h2E
olRemote = 47 ' &h2F
olTask = 48 ' &h30
olTaskRequest = 49 ' &h31
olTaskRequestUpdate = 50 ' &h32
olTaskRequestAccept = 51 ' &h33
olTaskRequestDecline = 52 ' &h34
olExplorers = 60 ' &h3C
olInspectors = 61 ' &h3D
olPanes = 62 ' &h3E
olOutlookBarPane = 63 ' &h3F
olOutlookBarStorage = 64 ' &h40
olOutlookBarGroups = 65 ' &h41
olOutlookBarGroup = 66 ' &h42
olOutlookBarShortcuts = 67 ' &h43
olOutlookBarShortcut = 68 ' &h44
olDistributionList = 69 ' &h45
olPropertyPageSite = 70 ' &h46
olPropertyPages = 71 ' &h47
olSyncObject = 72 ' &h48
olSyncObjects = 73 ' &h49
olSelection = 74 ' &h4A
olLink = 75 ' &h4B
olLinks = 76 ' &h4C
olSearch = 77 ' &h4D
olResults = 78 ' &h4E
olViews = 79 ' &h4F
olView = 80 ' &h50
olItemProperties = 98 ' &h62
olItemProperty = 99 ' &h63
olReminders = 100 ' &h64
olReminder = 101 ' &h65
End Enum

Public Enum OlOutlookBarViewType
olLargeIcon = 0 ' &h0
olSmallIcon = 1 ' &h1
End Enum

Public Enum OlPane
olOutlookBar = 1 ' &h1
olFolderList = 2 ' &h2
olPreview = 3 ' &h3
End Enum

Public Enum OlRecurrenceState
olApptNotRecurring = 0 ' &h0
olApptMaster = 1 ' &h1
olApptOccurrence = 2 ' &h2
olApptException = 3 ' &h3
End Enum

Public Enum OlRecurrenceType
olRecursDaily = 0 ' &h0
olRecursWeekly = 1 ' &h1
olRecursMonthly = 2 ' &h2
olRecursMonthNth = 3 ' &h3
olRecursYearly = 5 ' &h5
olRecursYearNth = 6 ' &h6
End Enum

Public Enum OlRemoteStatus
olRemoteStatusNone = 0 ' &h0
olUnMarked = 1 ' &h1
olMarkedForDownload = 2 ' &h2
olMarkedForCopy = 3 ' &h3
olMarkedForDelete = 4 ' &h4
End Enum

Public Enum OlResponseStatus
olResponseNone = 0 ' &h0
olResponseOrganized = 1 ' &h1
olResponseTentative = 2 ' &h2
olResponseAccepted = 3 ' &h3
olResponseDeclined = 4 ' &h4
olResponseNotResponded = 5 ' &h5
End Enum

Public Enum OlSaveAsType
olTXT = 0 ' &h0
olRTF = 1 ' &h1
olTemplate = 2 ' &h2
olMSG = 3 ' &h3
olDoc = 4 ' &h4
olHTML = 5 ' &h5
olVCard = 6 ' &h6
olVCal = 7 ' &h7
olICal = 8 ' &h8
End Enum

Public Enum OlSensitivity
olNormal = 0 ' &h0
olPersonal = 1 ' &h1
olPrivate = 2 ' &h2
olConfidential = 3 ' &h3
End Enum

Public Enum OlSortOrder
olSortNone = 0 ' &h0
olAscending = 1 ' &h1
olDescending = 2 ' &h2
End Enum

Public Enum OlTaskDelegationState
olTaskNotDelegated = 0 ' &h0
olTaskDelegationUnknown = 1 ' &h1
olTaskDelegationAccepted = 2 ' &h2
olTaskDelegationDeclined = 3 ' &h3
End Enum

Public Enum OlTaskOwnership
olNewTask = 0 ' &h0
olDelegatedTask = 1 ' &h1
olOwnTask = 2 ' &h2
End Enum

Public Enum OlTaskRecipientType
olUpdate = 2 ' &h2
olFinalStatus = 3 ' &h3
End Enum

Public Enum OlTaskResponse
olTaskSimple = 0 ' &h0
olTaskAssign = 1 ' &h1
olTaskAccept = 2 ' &h2
olTaskDecline = 3 ' &h3
End Enum

Public Enum OlTaskStatus
olTaskNotStarted = 0 ' &h0
olTaskInProgress = 1 ' &h1
olTaskComplete = 2 ' &h2
olTaskWaiting = 3 ' &h3
olTaskDeferred = 4 ' &h4
End Enum

Public Enum OlTrackingStatus
olTrackingNone = 0 ' &h0
olTrackingDelivered = 1 ' &h1
olTrackingNotDelivered = 2 ' &h2
olTrackingNotRead = 3 ' &h3
olTrackingRecallFailure = 4 ' &h4
olTrackingRecallSuccess = 5 ' &h5
olTrackingRead = 6 ' &h6
olTrackingReplied = 7 ' &h7
End Enum

Public Enum OlUserPropertyType
olOutlookInternal = 0 ' &h0
olText = 1 ' &h1
olNumber = 3 ' &h3
olDateTime = 5 ' &h5
olYesNo = 6 ' &h6
olDuration = 7 ' &h7
olKeywords = 11 ' &hB
olPercent = 12 ' &hC
olCurrency = 14 ' &hE
olFormula = 18 ' &h12
olCombination = 19 ' &h13
End Enum

Public Enum OlWindowState
olMaximized = 0 ' &h0
olMinimized = 1 ' &h1
olNormalWindow = 2 ' &h2
End Enum

Public Enum OlSyncState
olSyncStopped = 0 ' &h0
olSyncStarted = 1 ' &h1
End Enum

Public Enum OlBodyFormat
olFormatUnspecified = 0 ' &h0
olFormatPlain = 1 ' &h1
olFormatHTML = 2 ' &h2
olFormatRichText = 3 ' &h3
End Enum

Public Enum OlDownloadState
olHeaderOnly = 0 ' &h0
olFullItem = 1 ' &h1
End Enum

Public Enum OlOfficeDocItemsType
olExcelWorkSheetItem = 8 ' &h8
olWordDocumentItem = 9 ' &h9
olPowerPointShowItem = 10 ' &hA
End Enum

Public Enum OlViewSaveOption
olViewSaveOptionThisFolderEveryone = 0 ' &h0
olViewSaveOptionThisFolderOnlyMe = 1 ' &h1
olViewSaveOptionAllFoldersOfType = 2 ' &h2
End Enum

Public Enum OlViewType
olTableView = 0 ' &h0
olCardView = 1 ' &h1
olCalendarView = 2 ' &h2
olIconView = 3 ' &h3
olTimelineView = 4 ' &h4
End Enum

#End If
========== end module ==========
reidarT said:
It is not a silly question.
When I used early binding by referencing Outlook Lib. obj
in references I had
Dim omMail as MailItem, and
Set omMail = olkApp.CreateItem(olMailItem)
now I use
Dim omMail As Object
Dim olMailItem As Object
and I think here is where i NEED HELP

best regards
ReidarT
-----Opprinnelig melding-----
Hi Reidar

Sorry if this is a silly question, but have you declared the Outlook
constants you are using (for example, olMailItem)? If you have removed the
reference for late binding then you will need to do so.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

ReidarT said:
Here is the beginning of the code :
Private Sub HENInfo_Click()
Dim olkApp As Object
'Dim olkApp As Outlook.Application
Dim omMail As Object
Dim olMailItem As Object

If Me.epost <> "" Then
'On Error GoTo Hotelinfo_Err
Set olkApp = CreateObject("Outlook.Application")
'Here is the stop of the code
Set omMail = olkApp.CreateItem(olMailItem)
omMail.To = Forms!Grunndata_Frm!epost
omMail.Subject = "Information from sender."

best regards
Reidart

"Cheryl Fischer" <[email protected]> skrev i melding
Try this:

Set omMail = olkApp.CreateItem(olMailItem)

instead of this:

Set omMail = olkApp.CreateItem(omMail(olMailItem))


hth,

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

I have an application that uses OLE automation from Acess to Word and
Outlook.
I want to use late binding because of different versions of Word and
Outlook.

I use late binding for Word, and it works OK, but I haven't managed to
do
it
with Outlook.

I need: From, To, Subject and Attachment

Dim olkApp as Object
Set olkApp = CreateObject("Outlook.Application")
' from here I am confused
Dim omMail As Object
Dim olMailItem As Object
'Code stops here
Set omMail = olkApp.CreateItem(omMail(olMailItem))

Best regards
ReidarT


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top