![]() ![]() (But the sample demonstrates that these settings are not sufficient to enable updating.) Then, the procedure uses cnn1 to open the rst1 recordset based on an inner join of the Orders and Order Details tables. The form's CursorType and LockType properties permit updating. Next, the procedure instantiates a recordset, rst1. The procedure begins by instantiating a Connection object, cnn1, and pointing it at the Northwind database. Because the form uses the default CursorLocation property, the attempt to revise a field value generates a run-time error that the procedure traps. After assigning the form's Recordset property, the code browses the form and attempts to update a field value through the form. The following code sample demonstrates the syntax for dynamically assigning a recordset to a form. Chapter 12 extends this chapter's coverage of forms and explores topics that pertain particularly to the use of forms in Access projects (.adp files). If you assign an ADO recordset based on a single table to a form in an Access project (as opposed to an Access database file), your form will be read/write by default. The next sample we'll examine shows the syntax and behavior of a form based on the default CursorLocation property setting. To enable read/write access, you must explicitly assign the adUseClient intrinsic constant to the CursorLocation property setting of a recordset for a form. Your application is still read-only with the default CursorLocation property setting. It doesn't matter if your application specifies a keyset cursor. The form supports browsing, but users cannot add, update, or delete records through it. When you assign an ADO recordset with the default CursorLocation property setting, you create a read-only form. This assignment is only possible programmatically. Then, just assign the ADO recordset to the form's Recordset property, and your application can display that data in the form. Your application simply needs to create a recordset with the proper SQL statement for the Open method of an ADO recordset. For example, a single form can show sales for different employees, customers, date ranges, departments, and products. If a user opens the form without using the application, the form will not have a dynamic record source assignment, even if it was previously opened through the application.īy dynamically assigning a record source to a form, you can use the same form for different needs within a single application. When you dynamically assign a record source to a form, the source lasts as long as the form is open. The form is otherwise identical to the one shown in Figure 5-8. The samples in this section use a wizard-generated form that has its Record Source setting cleared. If your application does not logically have a default record source for a form, clearing the Record Source setting ensures that the form will never display data unless the application specifically assigns it to the form. Leaving the form's settings undisturbed avoids a form opening with #Name? in its text boxes when no dynamic record source assignment exists. When your application programmatically assigns a record source, it overrides the default setting.Įach of the two approaches has its advantages. This approach uses the AutoForm RecordSource property setting as a default record source. (When you view such a form without first dynamically assigning a record source to it, its text boxes initially open with the message "#Name?.) Second, you can leave the Record Source setting created by the AutoForm Wizard. ![]() First, you can clear the RecordSource property setting from the form's property sheet. There are two techniques for converting a form created by the AutoForm Wizard to one that is suitable for dynamic record source assignment. Taking advantage of this capability allows you to reduce the size of a database behind a form or take advantage of a record source that is already open, thus improving the form's load time. Dynamically assigning record sources to forms greatly increases their flexibility. After creating a bound form with the AutoForm Wizard, you can use the form for dynamic record source assignment.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |