Home
What's New
Dev Tools
Services
Feedback
Site Map

Having Wizard-generate Forms use an Application-level ADO Connection

ADO Wizard-generated forms establish their own form-level connection, by default. It is fairly straightforward to make the Wizard-generated form re-use the common application connection.  The steps are as follows.

Step 1: Option to Select when Generating the Form using using the Wizard
Step 2: Fixing Possible wizard-generated bugs
Step 3: Changing Wizard Code to use Application-level ADO DB Connection
Step 4: Clean-up: get rid of the now redundant form-level connection code

Step 1: Option to Select when Generating the Form using the Wizard

In the form-generation wizard, select "ADO Code" option when specifying "binding" type in Wizard. This option provides code-level control over the database connection.


Step 2: Fixing Possible Wizard-generated Bugs

VB6 (up to and including Service Pack 3) would sometimes generate code with compile/run-time bugs. To fix these problems:

After you have fixed these bugs and the form runs, you are ready to make the Wizard-generated form use the application level database connection.


Step 3: Changing the Wizard-generated Code to use the application-level ADO DB Connection

3.1 Find the recordset open statement that looks like:

datPrimaryRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly

3.2 Change the database connection to use the application connection (ours is called "db"):

datPrimaryRS.Open sSQL, db, adOpenForwardOnly, adLockReadOnly

Once this application-level connection works, you can remove the old form-level connection.


Step 4: Clean-up: Remove the Wizard code that Established the Form-level Connection

4.1 Remove the code that declared form-level connection:

 Dim sConnect As String
 Dim dfwConn As ADODB.Connection

4.2 remove code that established connection:

' open connection
Set dfwConn = New Connection
dfwConn.Open sConnect

Now the Wizard-generated form uses your application-level connection! Perhaps future versions of VB will let you specify your application-level database connection variable (instead of always creating a form-level connection).

... back to ADO Topics
Copyright © Woodger Computing Inc.