使用vba获得在ms access模块中使用intellisense(正式称为picklist)的能力,以引用任何现有对象(表、查询、窗体、报表)的控件。
我曾经非常依赖“我”,觉得它非常方便和有用,但从不喜欢它的局限性。
下面的解决方案是我开发的,并在我工作过的多个应用程序中实现的,作为“我”的替代方案。
'Function Declaration to use 'this.':
Dim this As Form_myFormName
Set this = Mee
'Function Declaration to use 'Mee.':
Dim Mee As Form_myFormName
Set Mee = this
'Function Code Module:
Public Property Get Mee() As Object
On Error Resume Next
Dim dbApp As ezGetElementBy
Set dbApp = New ezGetElementBy
 Set Mee = dbApp.obj
End Property
Public Property Get this() As Object
On Error Resume Next
Set this = Mee
End Property
'Class Module: ezGetElementBy
Public Function obj() As Object
On Error GoTo ErrHandler
Dim APP_OBJECT_NAME As String
Dim APP_OBJECT_TYPE As Integer
Dim dbObjectDesc As Variant
 APP_OBJECT_NAME = Application.CurrentObjectName
 APP_OBJECT_TYPE = Application.CurrentObjectType dbObjectDesc = Array("Table", "Query", "Form", "Report", "Macro", "Module")
 AsObjectType = IIf( _
  APP_OBJECT_TYPE = 2 Or APP_OBJECT_TYPE = 3, _
  dbObjectDesc(APP_OBJECT_TYPE), Object _
 )
 Select Case APP_OBJECT_TYPE
  Case 0 ' "Table"
   Set obj = Screen.ActiveDatasheet
  Case 1 ' "Query"
   Set obj = Screen.ActiveDatasheet
  Case 2 ' "Form"
   Set obj = Forms(APP_OBJECT_NAME)
  Case 3 ' "Report"
   Set obj = Reports(APP_OBJECT_NAME)
  Case Else
 End Select
Exit Function
ErrHandler:
On Error Resume Next
 Select Case APP_OBJECT_TYPE
  Case 0 ' "Table"
APP_OBJECT_NAME=Screen.ActiveDatasheet.Name
DoCmd.SelectObject acTable,APP_OBJECT_NAME, True
DoCmd.OpenTable APP_OBJECT_NAME, acViewNormal
Set obj = Screen.ActiveDatasheet
  Case 1 ' "Query"
APP_OBJECT_NAME=Screen.ActiveDatasheet.Name
DoCmd.SelectObject acQuery,APP_OBJECT_NAME, True
DoCmd.OpenQuery APP_OBJECT_NAME, acViewNormal
Set obj = Screen.ActiveDatasheet
  Case 2 ' "Form"
APP_OBJECT_NAME =Screen.ActiveForm.Name
DoCmd.SelectObject acForm,APP_OBJECT_NAME, True
DoCmd.OpenForm APP_OBJECT_NAME, acNormal, , , , acWindowNormal
Set obj = Screen.ActiveForm
  Case 3 ' "Report"
APP_OBJECT_NAME=Screen.ActiveReport.Name
DoCmd.SelectObject acReport, APP_OBJECT_NAME, True
DoCmd.OpenReport APP_OBJECT_NAME, acNormal, , , acWindowNormal
Set obj = Screen.ActiveReport
Case Else
End Select
Exit Function
End Function