Basing Forms on Queries: The Why and How
One strategy when building forms is to base them on queries; by doing this, you generally get optimal performance and flexibility. Rather than bringing all fields and all records over the network, you bring only the fields and records you need. The benefits are even more pronounced in a client/server environment where the query is run on the server. Even in an environment where data is stored in the proprietary Access file format (.mdb) on a file server, a form based on a stored query can take better advantage of Access's indexing and paging features. By basing a form on a query, you also have more control over which records are included in the form and in what order they appear. Finally, you can base a form on a query containing a one-to-many join, viewing parent and child information as if it were one record. Notice in Figure 5.41 that the client and project information appear on one form as if they were one record.
Figure 5.41. A form based on a one-to-many query.

Embedding SQL Statements Versus Stored Queries
In earlier versions of Access, stored queries offered better performance than embedded SQL statements. This is because when a query is saved, Access compiles the query and creates a query plan, which has information on the best way to execute the query based on available indexes and the volume of data. In earlier versions of Access, if a form was based on an embedded SQL statement, the SQL statement was compiled and optimized each time the form was opened. With Access 2002 and Access 2003 (as with Access 2000), embedded SQL statements are compiled just like stored queries. You might ask whether, with Access 2003, it is better to base a query on a stored query or on a SQL statement. My personal preference is as follows: If I plan to use the same or a similar query with multiple forms and reports, I build a query and base multiple forms and reports on that query. This keeps me from having to duplicate my efforts in building the query. If I have a query that is unique to the form, I build it as an embedded SQL statement. This eliminates the extra "clutter" of the query in the database container.Chapter 30, "Maintaining Your Application," covers the process of compacting your databases.