Screen 對象引用當(dāng)前擁有焦點(diǎn)的特定窗體、報(bào)表或控件。
使用 Screen 對象及其屬性,可以引用擁有焦點(diǎn)的窗體、報(bào)表或控件。
例如,可以使用 Screen 對象與 ActiveForm 屬性來引用活動窗口中的窗體而無需知道窗體的名稱。下面的示例將顯示活動窗口中窗體的名稱:
引用 Screen 對象并不會使窗體、報(bào)表或控件激活。為了激活窗體、報(bào)表或控件,必須使用 DoCmd 對象的 SelectObject 方法。
如果在沒有活動窗體、報(bào)表或控件的情況下引用 Screen 對象,Microsoft Access 會返回一個(gè)運(yùn)行時(shí)錯(cuò)誤。例如,如果某個(gè)標(biāo)準(zhǔn)模塊位于活動窗口,那么前面示例中的代碼就會返回一個(gè)錯(cuò)誤。
下面的示例將使用 Screen 對象來打印活動窗口中窗體的名稱及該窗體上活動控件的名稱:
Sub ActiveObjects()
Dim frm As Form, ctl As Control
' Return Form object pointing to active form.
Set frm = Screen.ActiveForm
MsgBox frm.Name & " is the active form."
' Return Control object pointing to active control.
Set ctl = Screen.ActiveControl
MsgBox ctl.Name & " is the active control " _
& "on this form."
End Sub