473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,387 developers and data experts.

ADO Events [Advanced Content]

ADezii
8,834 Expert 8TB
Not all ADO Power Users realize that there are Events, specifically related to the Connection and Recordset Objects, for which they can write code for. If one is aware of these Events, it is not exactly intuitive as to how you would access them. Below, please find a listing of Events which are exposed by the ADO Recordset and Connection Objects. I will also demonstrate the mechanism by which you, the ADO programmer, can make use of these valuable tools. An in-depth discussion of these Events is well beyond the scope of this Tip. It is solely my intention to make you aware of their existence, and also to demonstrate the means by which you can utilize these critical Events.
  1. Events of the ADO Recordset Object:
    1. FetchProgress()
    2. FetchComplete()
    3. WillChangeField()
    4. FieldChangeComplete()
    5. WillMove()
    6. MoveComplete()
    7. EndOfRecordset()
    8. WillChangeRecord()
    9. RecordChangeComplete()
    10. WillChangeRecordset()
    11. RecordsetChangeComplete

  2. Events of the ADO Connection Object:
    1. WillConnect()
    2. ConnectComplete()
    3. Disconnect()
    4. WillExecute()
    5. ExecuteComplete()
    6. BeginTransComplete()
    7. CommitTransComplete()
    8. RollbackTransComplete()
    9. InfoMessage()

  3. How to access ADO Event Procedures. The process involved in accessing ADO Events involves what is called an Event Sink. To sink to an ADO Event, you must:
    1. Set a Reference to the Microsoft ActiveX Data Objects X.X Library.
    2. Create a Class Module, either a stand-alone Class Module or a Form's Class Module.
    3. Add a WithEvents variable to the Module, preferably to the Declarations Section. WithEvents is a KeyWord that specifies that an Object Variable is to be used to respond to Events triggered by an ActiveX Object. Typical WithEvents Declarations follow:
      Expand|Select|Wrap|Line Numbers
      1. Private WithEvents cnn As ADODB.Connection
      2. Private WithEvents rst as ADODB.Recordset
    4. Once you add WithEvents to a Class Module, the VBA Editor adds the Event Sink Variable to the editor's drop down Object List. Once you select the Event Sink Variable from the Object drop down, the related Events to which you can respond, appear from the Procedures drop down List. To create one or more Event Procedures for that Event Sink, write code in the Procedure to react to that Event.
      Expand|Select|Wrap|Line Numbers
      1. Private Sub cnn_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
      2. 'The following code segment exists in a Form's Class Module
      3. 'display a Connected Message and enable specific Controls.
      4. 'disable the Connect Button and enable an Execute Button
      5. Me![lblConnect].Caption = "Connected to SQL Server Godzilla"
      6. Me![cmdConnect].Enabled = False
      7. Me![cmdExecute].Enabled = True
      8. End Sub
    5. Somewhere in your code - for example in the Form's Load Event, instantiate the Event Sink Variable. This step is actually out-of-sequence with the prior step. It was logical to demo the code in the prior step:
      Expand|Select|Wrap|Line Numbers
      1. Set rst = New ADODB.Recordset
    6. Somewhere else in your code - for example in the Form's UnLoad Event, destroy the Event Sink by setting it to nothing.
      Expand|Select|Wrap|Line Numbers
      1. Set rst = Nothing
Aug 12 '07 #1
0 13044

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Millissa | last post by:
If someone can help me with examples of or info on how to create an advanced tables for the layout on my site, I would be very grateful! Thanks, M
11
by: VK | last post by:
Hi, I'm playing around with tables (TOM vs. DOM etc.) I cannot figure out an effective highlight mechanics for the cells: 1) No problems with: <td ...onMouseOver/Out background change> some...
5
by: knocte | last post by:
Hello. I am a web developer very worried about "bloat code" and "languages mixture". So, since some time, I always try to avoid completely the use of javascript in XHTML/HTML files. This leads...
2
by: wobbles | last post by:
Hi Everyone (Happy New Year!), If I have clients that want to tell the server that something has happened, what would be the difference between "remoting events" and using an asynchronous (one...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
1
by: dezza | last post by:
Hi, I am developing a web application that is a series of pages, rather like a wizard. Because all of the pages basically have the same navigation, and require the navigation buttons in the...
30
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment...
3
pragathik
by: pragathik | last post by:
hi, below is my code <html> <body> <div> //HTML goes here with events like onclick,onchange </div>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.