Oorang
Well-known Member
- Joined
- Mar 4, 2005
- Messages
- 2,071
Hello all,
I am trying to create a function that returns the acObjectType type using just the object name. The function I built seems a little cumbersome I was wondering if anyone could suggest refinements:
I am trying to create a function that returns the acObjectType type using just the object name. The function I built seems a little cumbersome I was wondering if anyone could suggest refinements:
Code:
Private Sub Test()
MsgBox AccessObjectType("test")
End Sub
Private Function AccessObjectType(strObjName As String) As Access.AcObjectType
On Error Resume Next
'Written by Aaron Bush 10/19/2006
'Free for Public use, please retain Notice.
Dim ao As Access.AccessObject
Dim td As DAO.TableDef
Dim qd As DAO.QueryDef
Set ao = Access.CurrentProject.AllForms.Item(strObjName)
If Not ao Is Nothing Then
AccessObjectType = acForm
Exit Function
End If
Set ao = Access.CurrentProject.AllReports.Item(strObjName)
If Not ao Is Nothing Then
AccessObjectType = acReport
Exit Function
End If
Set ao = Access.CurrentProject.AllMacros.Item(strObjName)
If Not ao Is Nothing Then
AccessObjectType = acMacro
Exit Function
End If
Set ao = Access.CurrentProject.AllDataAccessPages.Item(strObjName)
If Not ao Is Nothing Then
AccessObjectType = acDataAccessPage
Exit Function
End If
Set ao = Access.CurrentProject.AllModules.Item(strObjName)
If Not ao Is Nothing Then
AccessObjectType = acModule
Exit Function
End If
For Each td In CurrentDb.TableDefs
If td.Name = strObjName Then
AccessObjectType = acTable
Exit Function
End If
Next td
For Each qd In CurrentDb.QueryDefs
If td.Name = strObjName Then
AccessObjectType = acQuery
Exit Function
End If
Next qd
AccessObjectType = acDefault
End Function