Sei sulla pagina 1di 11
srear2019 Form object (Access) | Microsoft Docs Form object (Access) 03/08/2019 + 4 minutes to read + Contributors 0@ 0 @ - all In this article Remarks Example Events Methods Properties See also A Form object refers to a particular Microsoft Access form. Remarks A Form object is a member of the Forms collection, which is a collection of all currently open forms. Within the Forms collection, individual forms are indexed beginning with zero. You can refer to an individual Form object in the Forms collection either by referring to the form by name, or by referring to its index within the collection If you want to refer to a specific form in the Forms collection, it's better to refer to the form by name because a forms collection index may change. If the form name includes a space, the name must be surrounded by brackets ([]). Syntax Example AllForms!formname Al1Forms !OrderForm AllForms!|form name] AllForms! [Order Form] AllForms(’formname") Al1Forns(“OrderForm”) AllForms(index) Al1Forms(@) Each Form object has a Controls collection, which contains all controls on the form. You can refer to a control on a form either by implicitly or explicitly referring to the Controls collection. Your code will be faster if you refer to the Controls collection implicitly, The following examples show two of the ways you might refer to a control named NewData on the form called OrderForm. hitps/idocs microsoft comen-usloficlvbalaplaccess form am srear2019 Form object (Access) | Microsoft Docs vB Bcopy Implicit reference. Forms !OrderForm!NewData vB Bcopy Explicit reference. Forms !OrderForm. Controls INewbata The next two examples show how you might refer to a control named NewData on a subform ctlSubForm contained in the form called OrderForm. vB Bcopy Forms !OrderForm.ct1SubForm.Form!Controls.NewData vB Bcopy Forms !OrderForm.ct1SubForm!NewData Example The following example shows how to use TextBox controls to supply date criteria for a query. vB Bcopy Private Sub cmdSearch_Click() Dim db As DAO.Database Dim qd As QueryDef Dim vihere As Variant Set db = Currentob() On Error Resume Next db.QueryDefs.Delete "Query" On Error GoTo @ vhere = Null. VWhere = vihere Samp; " AND [PayeeID]=" + Me.cboPayeeID Tf Nz(Me.txtEndDate, "") <> "" And Nz(Me.txtStartDate, Then hitps/idocs microsoft comen-usloficelvbalaplaccess form srear2019 Form object (Access) | Microsoft Docs vihere = vwhere Samp; Me.txtStartDate & Else If Nz(Me.txtEnddate, "") = "" And Nz(Me.txtStartDate, “") <> vithere = vWhere Samp; " AND [RefundProcessed]>: + Me.txtStartbate & "#" AND [RefundProcessed] Between #" & _ # AND #" Bamp; Me.txtEndDate & " Then Else Tf Nz(Me.txtEndbate, “") <> And Nz(Me.txtStartDate, “") Then vihere = vWhere & " AND [RefundProcessed] + Me.txtEndbate amp; " End If End If End If Tf Nz(vihere, “*) = "* Then MsgBox “There are no search criteria selected.” & vbCrLf & vbCrLf & _ "Search Cancelled.", vbInformation, "Search Canceled." Else Set qd = db.CreateQuerybeF("Queryi", "SELECT * FROM tblRefundoata? amps _ " WHERE " & Mid(vwhere, 6)) db.Close Set db = Nothing Docmd.OpenQuery "Query1", acViewNormal, acReadOnly End IF End Sub The following example shows how to use the BeforeUpdate event of a form to require that a value be entered into one control when another control also has data. vB Bcopy Private Sub Form_BeforeUpdate(Cancel As Integer) Tf (IsNull(Me.FieldOne)) Or (Me.FieldOne.Value = "No action required Then Else If (IsNull (Me.FieldTwo)) or (Me.FieldTwo.Value = "") Then MsgBox “You must provide data for field ‘FieldTwo', " & _ "if a value is entered in Fieldone", _ vbOKOnly, "Required Field” Me. FieldTwo.SetFocus Cancel = True Exit sub End If End If End Sub hitps/idocs microsoft comen-usloficlvbalaplaccess form am

Potrebbero piacerti anche