Microsoft Access VBA Open Form to a New or Specific Record

The VBA code is the feature in Ms Access for programming to adding more function to Access database, using Visual Basic. To open the VBA window, press the Alt + F11 buttons in your keyboard. The Open Form function is to open specific form when an action is occurred, such as when clicking button in a form. Even through the feature can be achieved with command button wizard, sometimes you may need to use it in VBA for more complex or specified result.

The general syntax for Open Form function:
DoCmd. OpenForm (FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)

Parameters:

FormName: the string contains name of the form. It is the only required parameter, the rest of the parameter below is optional.

View: determine how the form will be opened and presented. Values: acNormal (normal form), and acFormDS (datasheet).

FilterName: string that refers to the query name in the database

WhereCondition: it is same like SQL Where function. It is to extract specific result from the database.

DataMode: about how the data entry mode for the form. There are 3 values: acFormAdd (opens the form on a ‘new’ (empty) form, acFormEdit (allows editing), and acFormReadOnly (no editing allowed).

WindowMode: determine how the window mode in which the form opens, like pop up or not. The value are: acWindowNormal (Normal view), acDialog (dialog box), and PopUp.

Read Also:  MS Access Left Function in SQL Query and VBA Code

OpenArgs: the function to pass data to the form. The OpenArgs function can be used for several things, such as creating Modules, or procedure before opening the form. Sometimes, the OpenArgs is become the function instead the parameter for OpenForm, even though it still need to be used with OpenForm.

Example:
1. DoCmd. OpenForm (“MemberDetails”, acNormal, , , acFormEdit, PopUp)
This will open the MemberDetails form in Normal Mode, that can be edited and is a PopUp form.

Microsoft Access VBA Open Form 1

Microsoft Access VBA Open Form 1

2. DoCmd.OpenForm “BooksDetails”, , , , “FirstName = ’Danang’”
This will open the BooksDetails form, with condition only for Danang.

3. Example in Library Database

Microsoft Access VBA Open Form 2

Microsoft Access VBA Open Form 2

It will open the BookForm form, with CategoryID is BR. Read more tutorial for Microsoft Access VBA.



Access Database Tags: #ms access vba check to see if form is open #ms access vba on form open #ms access vba open form on new record #ms access vba open form on startup #ms access vba open form openargs #ms access vba open form popup #ms access vba open form read only #ms access vba open form specific record #ms access vba open form with parameters #ms access vba openform parameters #ms access vba refresh all open forms

Powershell Query MS Access Database in Microsoft Windows Application
Powershell Query MS Access Database in Microsoft Windows Application
Powershell Access Database – Ms. Powershell is
Microsoft Access Weekday and Week Number Function
Microsoft Access Weekday and Week Number Function
Ms Access Weekday Function is purposed to
MS Access VBA Close Workbook and Form
MS Access VBA Close Workbook and Form
In this tutorial, we use Ms Access


Must read×

Top