Microsoft Access 2010 tutorial:Docmd to open query


DoCmd.OpenQuery

VIII. DoCmd.OpenQuery

DoCmd.OpenQuery is a method used to open a query. By using this method, you can open a query in Design View, Datasheet View, PivotChart, PivotTable or Print Preview. It has the following syntax:

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
End Sub

Note: The name of Command Button is optional.


Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.