DoCmd.OpenQuery (QueryName, View, DataMode,)
- QueryName: It is the name of a query in the current database. It is a required argument. It must be written between double quotes.
- View: There are a few types of form's view such as acViewDesign, acViewNormal, acViewPreview, acViewLayout and so on. You can choose one among those types to specify your query when it opens.
- DataMode: This argument allows you to specify the data entry mode for your query. You can add data, edit data, or you can only read the data.Remark: All arguments in DoCmd.OpenQuery syntax are optional except QueryName argument.
For example, you want to open a query in Print Preview when you click Open Query button on the Form1. To do this task, you must apply the VBA code in CmdOpenQry_Click event procedure as the following:
Private Sub CmdOpenQry_Click()
DoCmd.OpenQuery "Query1", acViewPreview
Note: The name of Command Button is optional.
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: