Binding Datafields to Controls

Let's start with a very simple example, using an uncomplicated form, and a class module that we'll construct. We're going to create a class that will encapsulate the code to handle an ADO recordset for us. What we'll do here is bind two text boxes on our simple form to two fields in the Publishers table - a single button on the form will move us on to the next record. This is all pretty simple in terms of the functionality we'll use, but the principles involved will provide us with a good idea of how to extend this method.

Take another look at this illustration:

This is what our first program will accomplish without an ADO data control. So let's get on with the coding!

Try It Out - Create a Simple Bindings Collection

1.  Start a new project called

\Chapter12\Bindings.vbp
. Name the default form
frmBoundExample
. Add a class module and name it
myBoundClass
. Your Project Explorer should now look like this:

2.  Add two text boxes, a check box, and a command button to the form. Please lay out the controls like this:

Control Property Value
Text box
Name
txtPubID
Text
txtPubID
Text box
Name
txtName
Text
txtName
Checkbox
Caption
Show Message
Command Button
Name
cmdMoveNext
Caption
&Move Next

So much for the form. Next - the class module.

© 1998 by Wrox Press. All rights reserved.