To view the vba select statement in a query, while in design view of the query, below the File in the upper left you should see a drop down where you can select "Design View" or "SQL View" (plus some other options). Select "SQL View" to view the vba select statement (after you've added a table to the query and dragged some fields down to the grid below.) Also try designing a new query and going through the wizard (ie..Find Duplicates Query Wizard or Find Unmatched Query Wizard...etc..) The wizard will walk you through steps on setting up the query. Once you've finished the wizard, view the "SQL View" again to see the select statement the query wizard created. Also note that in design view of the query, you can select different query types (ie..Query -> Select Query, Update Query, Append Query, etc...etc...)
To view the vba code in a form, show the properties (ie. View -> Properties) while in design view of the form, click the events tab, select any event (ie. On Open...), click the dropdown at the right of this line (next to the ...), select [Event Procedure], and then click the ... - this then takes you to the vba code you write for when the form Opens (ie. On Open event). Or you can simply select View -> Code to see the coding in the form. In some examples from the Code Bank, you might notice code like the following in a form (for example some code someone wrote in the On Close event of the form):
Private Sub Form_Close()
The example code above is saying..."Quit the application when the Form closes." Each vba code for an event usually begins with a "Private..." and ends with an "End Sub" Looking at the Events tab in the properties in design view of the form, you will see [Event Procedure] for any event lines which have code for that event. Again clicking the ... takes you to the vba code for that event. NOTE: When you're viewing the vba code, you need to View -> Object to switch back to design view of the form (or click the upper right X to close the vba code view and go back to the object/design view of the form.) Also Note that if you click the upper right X in the vba code, it closes the vba code and goes to design view BUT if you click the upper right X while in design view of the form, Access exits! This is very easy to get mixed up and you may find yourself closing Access unexpectedly because you accidently clicked the upper right X while in design view (verses vba code view).
Notice that you can also write code for other events of the form (ie. On Current, Before Insert, After Insert, etc..etc..).
Add a text box control to the form (ie. View -> ToolBar -> Toolbox if it's not showing to see what kind of controls you can add to a form - hold the mouse over each control to see what type each one is which will show as you put the mouse over the control...ie..Label, Text Box, Option Group..etc...etc..) Click on the text box control on the Toolbox and then drag a box on the form. Then click on the text box you just made (viewing the properties of it ...View -> Properties if it's not showing) and you will notice that you can also write code against events for that text box (ie..Before Update, After Update, On Dirty, On Undo, etc..etc..) You click the dropdown for that event and select [Event Procedure] again and then click the ... to the right of the dropdown. You can write code in events against other types of controls of the ToolBox you put on the form (see Help for ToolBox controls.)
Using the Toolbox again, there is also a Command button. Click this and draw a square on the form, a wizard will appear where you can select from some options (ie..Record Navigation -> Find Next or -> Find Record, etc...etc... or Record Operations -> Add a New Record or -> Delete a Record, etc....etc..., Form Operations, -> etc..etc..) Once you go through the wizard (selecting one of the wizard items), then click on the button while still in design view of the form (again viewing the properties, events tab) and notice there is [Event Procedure] for the On Click. Click the ... to the right of that line to see what the wizard created for vba code depending on what you told the button to do via the wizard.
If you want help on what each event does, click on that event line and push the F1 key.
Try downloading some examples in the MSAccess Code Bank and notice some of the events programmed in for some of the forms or other controls in any of the example downloads.
Hope that helps.
Last edited by pkstormy; 08-23-07 at 22:56.
Expert Database Programming
MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)