Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



Determining the Type of a Control


When writing generic code, you might need to determine the type of a control. For example, you might want to loop through all the controls on a form and flip the Enabled property of all the command buttons. To do this, use the ControlType property of a control. Here's an example of how it's used (you can find this in Chap8Ex.mdb in the module called basExamples):

Sub FlipEnabled(frmAny As Form, ctlAny As Control)
'Declare a control object variable
Dim ctl As Control
'Loop through the Controls collection using the For..Each Construct
ctlAny.Enabled = True
ctlAny.SetFocus
For Each ctl In frmAny.Controls
'Evaluate the type of the control
If ctl.ControlType = acCommandButton Then
'Make sure that we don't try to disable the command button _
that invoked this routine
If ctl.Name <> ctlAny.Name Then
ctl.Enabled = Not ctl.Enabled
End If
End If
Next ctl
End Sub

The FlipEnabled procedure is called from the form frmTypeOf. Each command button on the form (Add, Edit, Delete, and so on) sends the form and the name of a control to the FlipEnabled routine. The control that it sends is the one that you want to receive the focus after the routine executes. In the example that follows, the code sends the cmdSave command button to the FlipEnabled routine. The FlipEnabled routine sets focus to the Save button:

Private Sub cmdAdd_Click()
'Call the FlipEnabled routine, passing references to the current form,
'and to the cmdSave command button on the current form
Call FlipEnabled(Me, Me.cmdSave)
End Sub

The FlipEnabled routine receives the form and control as parameters. It begins by enabling the command button that was passed to it and setting focus to it. The FlipEnabled routine then uses the VBA construct For...Each to loop through all the controls on a form. The For...Each construct repeats a group of statements for each object in an array or collectionin this case, the Controls collection. The code evaluates each control on the form to determine whether it's a command button. If it is, and it isn't the command button that was passed to the routine, the routine flips the control's Enabled property. The following VBA intrinsic controls are used when evaluating the ControlType property of a control:

Intrinsic Constant

Type of Control

acLabel

Label

acRectangle

Rectangle

acLine

Line

acImage

Image

acCommandButton

Command button

acOptionButton

Option button

acCheckBox

Check box

acOptionGroup

Option group

acBoundObjectFrame

Bound object frame

acTextBox

Text box

acListBox

List box

acComboBox

Combo box

acSubform

Subform/subreport

acObjectFrame

Unbound object frame or chart

acPageBreak

Page break

acPage

Page

acCustomControl

ActiveX (custom) control

acToggleButton

Toggle button

acTabCtl

Tab


/ 544