Late Binding

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Using Office XP and wish to email to Outlook from Access using vba - am
advised that usage of late binding would be preferable rather that setting
reference to Outlook

Does anyone have an example of the appropriate code please

TIA

Tom
 
Hi Tom,

Late Binding means that you declare all object variables As Object
instead of the proper object type. In this case you don´t need to
reference the Outlook library.

Anyway, if you are not familiar with the OOM, I would suppose that you
set a refenrence on Outlook while developing. After developing you can
remove this. Only with a reference set you can use the object browser
(F2), which shows you all available methods etc.

Create an Outlook instance with the CreateObject method, a MailItem with
the CreateItem method. Declarations and samples for using these methods
you will find easily via the object browser.

Please see also http://www.outlookcode.com/d/sec.htm for the upcoming
security warnings.
 
The project I just finished is using late-binding. The
only reason is to simplify the auto build process to
support different versions of Outlook.

The code would look like:

Dim oApp ' VBA
Dim oApp As Object ' VB6

Set oApp = CreateObject("Outlook.Application")

....

Set oApp = Nothing
 
Hi Bingo,
Dim oApp ' VBA

For VBS, ok, but why for VBA?

--
Viele Grüße
Michael Bauer



The project I just finished is using late-binding. The
only reason is to simplify the auto build process to
support different versions of Outlook.

The code would look like:

Dim oApp As Object ' VB6

Set oApp = CreateObject("Outlook.Application")

....

Set oApp = Nothing
 
VBScript indeed. :-)
-----Original Message-----
Hi Bingo,


For VBS, ok, but why for VBA?

--
Viele Grüße
Michael Bauer



The project I just finished is using late-binding. The
only reason is to simplify the auto build process to
support different versions of Outlook.

The code would look like:

Dim oApp As Object ' VB6

Set oApp = CreateObject("Outlook.Application")

....

Set oApp = Nothing



.
 
Thanks for your input, have tried your suggestions as per code below - it
will not compile last line saying user type not defined - what do I have to
declare olMailItem as?

Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object

Set objOutlook = CreateObject("Outlook.Application")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

Tom

VBScript indeed. :-)
 
Hi Tom,
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

with late binding you need to declare your own constants, i.e.
olMailItem from the Outlook Library is unknown for your app.
 
Hi Tom,

sorry, VBS is not my language and I´ve just read that constants aren´t
possible. That is you need to use the numeric value (0 for olMailItem).
 
Michael

Where can I find the numeric values for or do you know them for:

olTo
olCC
olBCC


tia

Tom
 
Hi Tom,

please set (for developing purposes only) a reference on the Outlook x.0
Library and open the object browser, as i mentioned earlier. You can
then type in all the constants you need and see their values below in
the description pane.
 
Once you have those Const values you can then define them in your VBS code
if you want using a Const declaration. VBS does support constant
declarations.
 
Back
Top