Microsoft Access 2010 tutorial:Docmd to open table


DoCmd.OpenTable

VII. DoCmd.OpenTable

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

DoCmd.OpenTable (TableName, View, DataMode,)

- TableName: It is the name of a table 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, and so on. You can choose one among those view types.

- DataMode: This argument allows you to specify the data entry mode for your table. You can add data, edit data, or you can only read the data.

Remark: All arguments in DoCmd.OpenTable syntax are optional except TableName argument.

For example, you want to open a table in Datasheet View with add new data mode when you click Open Table button on the Form1. To do this task, you must apply the VBA code in CmdOpenTable_Click event procedure as the following:

Private Sub CmdOpenTable_Click()
      DoCmd.OpenTable "TblBook", acViewNormal, acAdd
End Sub

Note: The name of Command Button is optional.




Comments

Rahat comment

 Rahat

How user will add new record it returns nothing(means table object) . how the fields will be accessed through code


2016-11-30



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.