• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 27. Understanding Universal Data... > Binding Controls to a Recordset with...

Binding Controls to a Recordset with Code

Adding the equivalent of bound controls to a form requires that you first add unbound controls and then bind the controls to the form's underlying Recordset with code. To create a simple data display form for the Customers table, do the following:

  1. Add seven unbound text boxes to the form. Name the text boxes txtCustID, txtCompanyName, txtAddress, txtCity, txtRegion, txtPostalCode, and txtCountry. Change the width of the text boxes to reflect approximately the number of characters in each of the Customer table's fields.

  2. Change the label captions to CustID, Name, Address, City, Region, Postal Code, and Country, respectively. Apply the Bold attribute to the labels for readability (see Figure 27.6).

    Figure 27.6. Text boxes to display the first seven fields of the Customers table.

  3. To bind the ControlSource property of each text box to the appropriate field of the Customers table, click the Code button and add the following lines of code immediately after the Set Me.Recordset = rstNwind line:

    Me.txtCustID.ControlSource = "CustomerID"
    Me.txtCompanyName.ControlSource = "CompanyName"
    Me.txtAddress.ControlSource = "Address"
    Me.txtCity.ControlSource = "City"
    Me.txtRegion.ControlSource = "Region"
    Me.txtPostalCode.ControlSource = "PostalCode"
    Me.txtCountry.ControlSource = "Country"
  4. Run the form in the default Single Form view and navigate the Recordset (see Figure 27.7).

    Figure 27.7. The form of Figure 27.6 in Single Form view.

  5. Change to Design mode and change the Default View property to Datasheet.

  6. Run the form again. The seven fields of the text boxes provide data to the columns of the datasheet, and the label captions serve as column headers (see Figure 27.8).

    Figure 27.8. The form of Figure 27.6 in Datasheet view.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint