Implementing An ADO Data Control With VB6 - Adding the remaining controls (Page 3 of 4 )
Add the appropriate label and text box controls until your form resembles the one shown in Figure A. Set each text box control's DataSource property to adoData (or the name of your ADO data control) to bind the text box to the data control.
Now you need to bind each control to a field. To do so, select a field from the text box control's DataField property. It's also a good idea to name each control. The table below lists the names we chose for our controls:
Quick Tip: You can save time when creating several controls of the same type by creating one control and setting all the shared properties. Then, use the Copy and Paste commands to create the total number of controls you'll need.
When VB asks if you’re creating a control array, answer "No". Once you have all the controls you need, simply select them individually and enter the unique properties -- such as the Name property. Now, let's finish our form by adding the last control -- a command button. Name that button cmdExit.
If you like, add the caption property E&xit. At this point, double-click the command button to open the form's module and add the procedure shown below. Close the window to return to your form.
Private Sub cmdExitCommand_Click() Unload frmDataControl End Sub
Running The Project At this point you're ready to run the project, so click F5. The form (in Figure A) displays the first record in the bound table (from Nwind.mdb). Click the navigational controls to move from one record to another. Remember that if you change the data in a record and then move to another record, VB will save the changes.
Try to add a new record by first clicking the Last button and then clicking the Next button. The first click will display the last record in the bound table. The second click will display a blank record (if you've set the data control's properties accordingly). If your form doesn't display a blank record then return to Design View, select the ADO data control and change it's EOFAction property to 2 - adDoAddNew.
Once you view a blank (new) record, you may encounter a problem if you try to return to a previous record. If your form includes any required fields, VB won't let you leave the new record until you enter something in the required fields. This behavior includes primary key fields and any required fields you may not have displayed on your form. You can however, exit your form by clicking the Exit command button.