Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Early and Late bilinding in ADO/DAO

    Hi,

    Can you please explaine pros n cons of Early and Late binding while using DAO/ADO connections.

    an example will be good. thanks in advance

  2. #2
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Praha
    Posts
    990
    Thanks
    56
    Thanked 105 Times in 90 Posts
    The differences are almost entirely in the execution within VBA rather than applying to a specific external use - maybe have a read of this, particularly the section titled Advantages of Early Binding . . . http://msdn.microsoft.com/en-us/library/0tcf61s1.aspx

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Paddydive,

    As I see it Early Binding is best while you are developing as it gives you access to the intellesense features of the VBA environment.
    Late Binding is best for the delivered software so users don't have to set references or worry about having Office 2010 when the software is expecting Office 2003 resulting in broken references and errors popping up when the code is run.

    When I develop I use the conditional compilation features built in to the VBE.

    Ex:
    Code:
    'Set Compiler Constant for Early/Late Binding conditional code
    ' 0 = Early Binding
    ' 1 = Late Binding
    
    'Set in Tools->ARB Properties... Global Scope if set here Module Scope
    
    #Const LateBinding = 1 '0 = Early Binding {for debugging/coding} 1 = Late Binding
    #Const MyDebug = 0     '0 = No Debug  1 = Debug Active
    
    #If LateBinding = 0 Then
       Dim oWordApp  As New Word.Application  'Use this for Early Binding
    #Else
       Dim oWordApp  As Object
       Const wdAlignTabLeft As Long = 0, wdAlignTabCenter = 1, wdAlignTabRight = 2
       Const wdAlignTabDecimal As Long = 3, wdAlignTabBar = 4, wdAlignTabList = 6
       Const wdTabLeaderLines As Long = 3, wdTabLeaderHeavy = 4, wdTabLeaderMiddleDot = 5
    #End If
    ----------------------------------------------------------------------------------------------
    
    #If LateBinding = 0 Then
    #Else
       Set oWordApp = CreateObject(Class:="Word.Application")
    #End If
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. The Following User Says Thank You to RetiredGeek For This Useful Post:

    Browni (2013-03-26)

  5. #4
    WS Lounge VIP Browni's Avatar
    Join Date
    Dec 2009
    Location
    Rochdale, UK
    Posts
    1,653
    Thanks
    38
    Thanked 161 Times in 139 Posts
    Thanks RG,

    I have always used early binding in my VBA exploits and can now appreciate where late binding would be of benefit.

  6. #5
    New Lounger
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by RetiredGeek View Post
    Paddydive,

    Early Binding is best while you are developing...Late Binding is best for the delivered software
    Thanks RG and MartinM,

    I was facing the above quoted problem and wanted to understand, and you explained it well... thanks a ton.

    Just few more little question, hope u wont mind...

    In late binding for Word application u used - Set oWordApp = CreateObject(Class:="Word.Application")

    - Will the 0WordApp hold a object of a available version of Word on the particular machine (say if a machine has 2003 or 2007 etc) ?
    - For Word you have used class as Word.application, if I want to use it for other application like Access,powerpoint or FileSystemObject, where will i
    get a name for that particular class. In short do we have a list of class names from where we can refer to it ?

    Thanks

  7. #6
    2 Star Lounger
    Join Date
    Dec 2009
    Location
    Dallas, Texas, USA
    Posts
    113
    Thanks
    3
    Thanked 6 Times in 6 Posts
    Yes, because the Program ID, Word.Application, is generic. It always corresponds to the most recently installed version of Microsoft Word.
    David Gray, Chief Wizard
    WizardWrx
    Irving, Texas, USA

    WizardWrx Web - Technical Articles and Free Software
    You are more important than any technology we may employ.

  8. #7
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Paddydive,

    You can google it, e.g. "vba createobject" w/o the quotes. One of the sites is the Microsoft Developers Network (MSDN) entry here. That entry has a link to OLE Programmatic Identifiers. Which has the information you want although you have to do a bit of scrolling. HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  9. #8
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,829
    Thanks
    136
    Thanked 482 Times in 459 Posts
    As mentioned in RG's post, with early binding you can use the intellisense in vba.
    So you can also use associated predefined constants.

    This means when using late binding, you cannot directly use these named constants.
    Which is why RG 'defines them' in his example in post#3

    zeddy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •