What is the difference between early binding and late
binding?

Answer Posted / murugesh

The process of verifying that an Object exists and that a
specified Property or Method is valid is called Binding.
There are two times when this verification process can take
place: during compile time (Early Binding) or run time
(Late Binding). When you declare an Object Variable as a
specific Data Type, you are using Early Binding so the
verification can take place during compile time. When you
declare a Variable of the generic Object Data Type, you are
using Late Binding. In this case, VBA must find and verify
the Object information during any execution of VBA
statement that includes a Reference to the Object or one of
its Properties or Methods. The time difference between
Early and Late Binding can be quite significant. Some
examples of Early Binding are listed below:
Dim appAccess As Access.Application
Dim appExcel As Excel.Application
Dim winExcel As Excel.Window
Dim winProject As Project.Window
Dim chkBox As CheckBox
Dim cboFinance As ComboBox
Dim chtMain As Chart
Dim lstLookup As ListBox
Dim pvtNew As PivotTable
As an example, I'll refer to an ADO Field as an ADODB.Field
and also as an Object (commented out). Benchmark Test
Procedures using the code below report a hugh difference in
the speed of accessing the ADO Field's Properties,
naturally, in favor of Early Binding. The code is listed
below.

Code: ( text )
Dim rst As ADODB.Recordset, strName As String

'Early Binding. Declaring fld as ADODB.Field results in
'times that are around 7% of those measured declaring fld
'as Object. In the case of several hundred Records, the
difference
'would not be significant, but in the case of several
hundred
'thousand Records, the time difference would be enormous.
Dim fld As ADODB.Field

'Late Binding
'Dim fld As Object

Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.Source = "tblEmployee"
rst.CursorType = adOpenStatic

rst.Open

rst.MoveFirst

Set fld = rst.Fields(0)
Do While Not rst.EOF
strName = fld.Name
rst.MoveNext
Loop

rst.Close
Set fld = Nothing
Set rst = Nothing

In every case, if at all possible, declare a Variable using
the most specific Object Type that you can. For Access
Controls, that means using, for example:

Code: ( text )
Dim cmd As CommandButton

Is This Answer Correct ?    15 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between change event in normal combobox and dbcombobox?

1664


How do I force a file dialogue box to reread the currect disk?

962


how to use unicode data in vb6 regarding to telugu language, my output is in only telugu language

3100


How do you change the system menu (on the Control-Menu Box)?

981


Types of ActiveX Components in VB?

1464






What is the use of Hyperlink control for DHTML applications?

1943


what are the Default cursor Type and LockEdit type in DAO?

1741


Draw Sequence Modal of DAO and Explain?

1511


Is it possible to Manipulate data through flexgrid? Explain.

1572


which property used to add a menus at runtime?

1479


How do you change the icon and otherwise manipulate the DOS box?

1107


___ is a property to resize a label control according to your caption.

1112


Explain about form creation in Visual Basic?

580


Explain the working of templates?

580


What is the use of ActiveX Documents?

1946