Mimic a Form_Activate Event for Popup forms (1 Viewer)

RailwayKen

New member
Local time
Today, 06:11
Joined
Dec 7, 2011
Messages
8
Please accept apologies for a very long question...

I wish to display all the forms and reports (in a database with 40+ forms) as popups, just because I think the user interface will be better if the form windows are not bound to the main Access window.

Most of the forms are opened using an object variable array
Code:
Public objFrm(19) as object
It is common to have more than one instance of a form open at the same time (each instance displaying a different record-- and no, I doubt anyone actually opens 20 forms at once-- objFrm's size is arbitrary). When a new instance of a form is opened, it is placed in objFrm using the lowest spot in the array that is not already in use. The form's number in the object array is stored on each form in a hidden textbox named "objFrm".

Trouble is popup forms do not trigger a Form_Activate event and 9 of my forms use one. So I am trying to mimic a Form_Activate using other means.

I've tried trapping for various other Form events, but the only event that fires when switching between open popup forms is the GotFocus for a control in the activated form. So the best solution I have come up with is to place the following in a module
Code:
Public PrevFrm as integer

Public Function GotFocus(f as integer)
[COLOR="SeaGreen"]     'If the previous control to have the focus is not
     'on the same form as the control getting the focus,
     'then I must have switched forms.[/COLOR]
     If PrevFrm <> f then
          PrevFrm = f
          Select Case objFrm(f).name
          Case "Form1"
                [COLOR="SeaGreen"]'Form Activate code for Form1[/COLOR]
          Case "Form2"
                [COLOR="SeaGreen"]'Form Activate code for Form 2[/COLOR]
          [COLOR="SeaGreen"]'Case ...[/COLOR]

          Case Else
               [COLOR="SeaGreen"]'do nothing[/COLOR]
          End Select
     End if
End Function

Then I would need to set the OnGotFocus property for each control in every form to:

"=GotFocus([objFrm])" ([objFrm] refers to a textbox on the form)

I have several hundred controls, so I could write code to set this property for me (nested For...Each loops, looping through every form in design mode, looping through each control).

I'm sure all of this would work, but it seems all this is beyond overkill as a way to replace nine Form_Activate events.

Surely someone has a better solution?
 

RailwayKen

New member
Local time
Today, 06:11
Joined
Dec 7, 2011
Messages
8
My proposed solution is faulty. The GotFocus for a control for a Pop-up form will not fire when the form activates if that control had the focus the previous time the popup was active.

So again my original question: how to get an event to fire when an open popup form becomes the top-most window again? Any ideas? Seems like I must be missing something obvious?
 

Users who are viewing this thread

Top Bottom