For the fun of it, just playing around with the latter one, returning both the type of object, and if form or report, also the name through an UDT.
[tt]Enum WassIt
Form
Report
Dunno
End Enum
Type WossName
Name As String
Type As WassIt
End Type
Function GetActiveObjectType() As WossName
Dim strName As String
Dim udtWossName As WossName
On Error Resume Next
With udtWossName
strName = Screen.ActiveForm.Name
If Err.Number = 0 Then
.Type = Form
Else
Err.Clear
strName = Screen.ActiveReport.Name
If Err.Number = 0 Then
.Type = Report
Else
.Type = Dunno
' strName = "Haven't the foggiest..."
Err.Clear
End If
End If
.Name = strName
End With
GetActiveObjectType = udtWossName
End Function[/tt]
So, I think the bottom line here, is that the "brute force" method - i e triggering an exception, is probably the way to go with native methods.
Here's a little sample call of hiding active object, if it's form or report
[tt] Dim udtWossName As WossName
udtWossName = GetActiveObjectType
Select Case udtWossName.Type
Case WassIt.Form
Forms(udtWossName.Name).Visible = False
Case WassIt.Report
Reports(udtWossName.Name).Visible = False
Case Else
MsgBox "OI - nothing has focus ..."
End Select[/tt]
(Type 0 = Form, 1 = Report, 2 = Dunno - or use as above)
But - I'm just thinking - these focus stuff thingies might be somewhat unreliable - wouldn't looping the forms/reports collection (collection of open forms/reports) be a more safe method of determining which form or report is open?
Roy-Vidar