'Determines the view of the current object Public Function ObjView(Optional objname As Variant, _ Optional objtype As Variant) As Variant Dim strObjectName As String Dim strObjectType As String Dim intView As Integer Dim obj As AccessObject 'determine whether the object is 'selected or passed via arguments If IsMissing(objtype) = True Then 'if using current object strObjectName = Application.CurrentObjectName strObjectType = Application.CurrentObjectType Else 'if using passed arguments strObjectName = objname strObjectType = objtype End If 'errHandler catches closed objects, tables, and queries, 'latter two don't support the CurrentView property On Error GoTo ErrHandler Select Case strObjectType Case Is = acTable Set obj = Application.CurrentProject.AllTables(strObjectName) intView = obj.CurrentView Case Is = acQuery Set obj = Application.CurrentProject.AllQueries(strObjectName) intView = obj.CurrentView Case Is = acForm Set obj = Application.CurrentProject.AllForms(strObjectName) intView = obj.CurrentView Case Is = acReport Set obj = Application.CurrentProject.AllReports(strObjectName) intView = obj.CurrentView Case Is = acMacro Set obj = Application.CurrentProject.AllMacros(strObjectName) intView = obj.CurrentView Case Is = acModule Set obj = Application.CurrentProject.AllModules(strObjectName) intView = obj.CurrentView Case Is = acDataAccessPage Set obj = Application.CurrentProject.AllDataAccessPages(strObjectName) intView = obj.CurrentView Case Is = acServerView Set obj = Application.CurrentProject.AllViews(strObjectName) intView = obj.CurrentView Case Is = acDiagram Set obj = Application.CurrentProject.AllDatabaseDiagrams(strObjectName) intView = obj.CurrentView Case Is = acStoredProcedure Set obj = Application.CurrentProject.AllStoredProcedures(strObjectName) intView = obj.CurrentView End Select ObjView = intView Exit Function ErrHandler: If Err.Number = 2467 Then MsgBox strObjectName & " " & "is closed", vbOKOnly, "Error" ObjView = adStateClosed ElseIf Err.Number = 438 Then MsgBox "The current object type isn't supported", vbOKOnly, "Error" ObjView = Empty 'may want to call ObjState to determine 'object's state. Else MsgBox Err.Description, vbOKOnly, "Error" ObjView = Empty End If End Function |