Try the following syntax and make sure that error handling is included in
your procedure (otherwise, an unfriendly, confusing Access error will be
displayed to the user):
Private Sub ActiveFormBtn_Click()
On Error GoTo ErrHandler
If (Screen.ActiveForm.Name = Forms("receiptsF").Name) Then
MsgBox "It's the active form.", vbInformation + vbOKOnly, _
" Found Active Form"
Else
MsgBox "It's not the active form.", vbInformation + vbOKOnly, _
"Form Open, But Not Active"
End If
Exit Sub
ErrHandler:
If (Err.Number = 2450) Then
MsgBox "This form isn't open.", vbInformation + vbOKOnly, _
" Form Not Found"
Else
MsgBox "Error in ActiveFormBtn_Click( )" & vbCrLf & "in " & _
Me.Name & " form." & vbCrLf & vbCrLf & "Error #" & _
Err.Number & vbCrLf & Err.Description
Err.Clear
End If
End Sub
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
dshemesh said:
Thank you,
I am trying to use it, but i get a 'type mismatch' error.
I want to check if a form called 'receiptsF' is active, so i wrote:
If (screen.ActiveForm([forms]![receiptsF])) Then ...
I tried looking in Qbuilt, but didn't find an answer there.
Does anybody know the exact syntax?
Thanks
'69 Camaro said:
Hi.
Use Screen.ActiveForm.Name to determine the name of the active form.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)