Share via

Screen.ActiveForm Message "...requires a form..."

Anonymous
2018-02-24T19:54:42+00:00

When I use the F1 key to request a Help File response from my Switchboard, I get a message "You entered an expression that requires a form to be the active window."  This is (normally) the only time I get that message.  Is there a way that I can tell Access (or Windows) that it is active?  Or a way I can intercept that test and call the help message (from a .chm file) sort of manually?

Gordon

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2018-02-24T23:38:09+00:00

So apparently your switchboard isn't always the active form, even when it appears to be.  Does the problem occur when only the switchboard form is open?  Is there any open form, visible or not, that has a Timer event running?

How are you trapping the pressing of the F1 key?  Is it by an autokeys macro, or the form's KeyDown event, or something else?

I suppose you might try a code loop to attempt to get the active form if something is intermittently stealing the focus.  It could loop for a fraction of a second until it has an active form;  something like this:

'----- start of code -----

Function GetActiveForm() As Access.Form

    Dim frm As Access.Form

    Dim lngTimerValue As Long

    On Error Resume Next

    lngTimerValue = Timer

    Do

        Set frm = Screen.ActiveForm

        If frm Is Nothing Then

            DoEvents

            ' Exit loop if more than a tenth of a second has gone by

            If Timer - lngTimerValue > 0.1 Then Exit Do

        End If

    Loop Until Not frm Is Nothing

    Set GetActiveForm = frm

End Function

'----- end of code -----

Was this answer helpful?

0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2018-02-25T21:36:04+00:00

    I see.  So on KeyDown you were calling your F1 Autokeys macro directly, but at the same that F1 Autokeys macro would also be invoked by the Autokeys functionality itself.  So it was stepping on its own toes.  Well spotted!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2018-02-25T21:16:35+00:00

    Well, Dirk, you led me indirectly to the source of the problem.  Your code allowed me to crawl around a bit more, and prompted me to try to use AutoKey and KeyDown.  When I got to the Property Sheet for On KeyDown, I noticed it had an entry "AutoKeys.{F1}" where there would normally be a [Event Procedure].  I checked another form, and it had nothing there, so I removed the F1 entry from the On Key Down line and voila! it now works the way it should.

    THANKS A BUNCH FOR TAKING THE TIME TO HELP ME!  :-)

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2018-02-24T23:00:30+00:00

    I have a church management program, name of CBW5.mdb (ChurchBook/Windows 5) with a help file that has been developed over a number of years.  In addition to reading the "book", it has linkage to forms in the program that deal with the form.  My "Switchboard" is an old-timer: buttons to take the user to sub-forms or directly to apps.  When the 2008 changes came about, I had to re-write and for some unknown (to me) reason, only the switchboard doesn't respond to the F1 key.  Sometimes it responds to Ctrl+F1 or just the Ctrl before I can click the F1.  When it is misbehaving with just the F1, it gives the  message "You entered an expression that requires a form to be the active window."  The following is the code that sets up the display of the help file sections:

    **********

    Public Function HelpEntry()

    Dim FormHelpID as Long

    Dim FormHelpFIle as String

    Dim curForm as Form

    Dim strS as string

    'Set the curForm variable to the currently active form

    Set curForm = Screen.ActiveForm

    ....

    **************

    Below this entry are other lines that provide for a default path, linkage to help buttons, and nulls.  They all work if I get beyond this one instruction.  I couldn't get this section to paste copies, but the problem occurs right at the one instruction "Set curForm = Screen.ActiveForm".  It generates the above message.  I have put code ahead of this line to see what it is saying, and sometimes I can get it to give me the name (Switchboard), but as soon as it hits the "real" code, I get the error message again. 

    For a while I was just intercepting the F1 and giving a message telling the users to open the CBW5Help.chm outside of the Access program.  Tacky.  So I've spent about a day and a half trying to find out how to get around this.  Hope you can help!

    Gordon

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2018-02-24T22:30:54+00:00

    What is the nature of your Switchboard?  Is it the built-in Switchboard form, or something else?

    Have you set up your own Help topics and set the form's Help File property?  Or else what mechanism have you set up to display the help?  Your thread title mentions "Screen.ActiveForm", but you haven't described anything that refers to Screen.ActiveForm, so I don't know where that comes from.

    Was this answer helpful?

    0 comments No comments