OpenForm


Opens a form in the current database.

Syntax

DoCmd.OpenForm(FormName[, View][, FilterName][, WhereCondition][,    DataMode][, WindowMode][, OpenArgs])

with the following parameters:

FormName

A String indicating the name of the form to open.

View

An AcFormView constant indicating the view in which to open FormName. Possible values are acDesign (design view), acFormDS (a datasheet), acFormPivotChart (a pivot chart), acFormPivotTable (a pivot table), acNormal (normal view, the default), and acPreview (print preview).

FilterName

A String containing the name of a query in the current database.

WhereCondition

A String containing a valid SQL WHERE clause (without the WHERE keyword).

DataMode

An AcFormOpenDataMode constant that defines the mode in which the form is opened. Possible values are acFormAdd (the user can add new records but can’t edit existing ones), acFormEdit (the user can edit existing records and add new ones, acFormPropertySettings (the mode is determined by the form’s existing property values, which is the default value), and acFormReadOnly (the form is read-only).

WindowMode

An AcWindowMode constant that determines the state of the form’s window. Possible values are acDialog (sets the form’s Modal and Popup properties to Yes), acHidden (the form is not visible), acIcon (the form is minimized), and acWindowNormal (the form is opened based on its property settings, which is the default).

OpenArgs

A value to be assigned to the form’s OpenArgs property. Typically, this is used to take some custom action in the form’s Load or Open event procedure. For example, you might want a multi-page form to open to a particular page. In that case, you’d open the form as follows:

DoCmd.openForm “MultiPageForm”, acNormal, , , acFormReadOnly, , 3

You can then go to the third page of the form by using the following event handler:

Private Sub Form_Open(Cancel As Integer)   DoCmd.GoToPage 3 End Sub

Example

The example prompts the user for a sales representative number, then displays a list of his or her customers.

Public Sub OpenSalesRepList() Dim intSalesRep As Integer Dim sInput As String sInput = InputBox("Enter Sales Rep Number: ") If Not IsNumeric(sInput) Then   Exit Sub Else   intSalesRep = CInt(sInput) End If DoCmd.OpenForm "frmRegional", , , "intSalesRep = " & intSalesRep, _   acFormReadOnly End Sub 

Comments

The various arguments to the function, and particularly the ability to override the form’s preassigned or default property values (like the Visible property or the EventArgs property), give the OpenForm function enormous power and flexibility.




Access VBA Programming
Microsoft Access VBA Programming for the Absolute Beginner
ISBN: 1598633937
EAN: 2147483647
Year: 2006
Pages: 214
Authors: Michael Vine

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net