Identifying the Active Form

  • Thread starter Thread starter Oddball279
  • Start date Start date
O

Oddball279

Guest
Apologises if the answer is out there somewhere but I have searched to no avail.

I have a number of Forms which the user can jump around from one to the next. All the forms remain open with the form they are currently viewing showing on top. If they make a change on one particular form then when they return to a previously viewed form I want to disable or hide certain certain controls etc.

I know this would be simple to do on the on open command but as previously mentioned as I am not closing the forms after they are viewed, if the user returns to a previously opened form then this is not picked up.

Soooo, basically I'm after something like

When the user moves from one form to another already opened form for the new form to immediately know that it now has the focus and for it to do something along the lines of on open.

Any help will be appreciated
 
I think the Activate event may be what you're looking for.
 
Unfortunately, I've tried the following but with a negative result

On Current
On Activate
On Got Focus
On Load
On Dirty
Befoe Update

I even tried bringing the focus to the form that I am moving to by inserting

Forms!FrmTblMain.SetFocus

In the on click procedure of the navigation button that I am using to get from one form to the next.

All of these failed to work so I suspect its a little bit more complicated than I realise.

That said, on reading the microsoft online help about on activate it appears to be what I'm after though for the life of me I cant get it to work (For testing purposes I've just dropped a msgbox into the on activate which fails to work on the form being selected)

Can any one help me out on this one as I'm sure its something others must have come across.
 
I am having a similar problem with the ACTIVATE event. I have a FORMA which opens FORMB. (FORMA is still "open" but behind FORMB) When FORMB closes I expected that the ACTIVATE event would trigger for FORMA since it is now the "active" form, but it does not. Also the FOCUS event was not triggered in FORMA. I assumed that focus event would also occur when FORMA returned to being the "active" form.

I need to trigger an event for FORMA to update various controls.

An alternative would be to add code to the command button that closes FORMB that forces FORMA to refresh. I have shied away from this approach since FORMB can be opened by a variety of other forms, and I will need to know the name of the calling (underlying) form. I could add a textbox in FORMB, where FORMA passes its name. Anyway, I am curious as to why the ACTIVATE event is not being triggered.
 
Try this :

On FormA create a textbox and give it a name - eg textF
(set the visible property to no if you don't want to see it)

On FormA ActivateEvent enter the code textF.setfocus

On the gotfocus event for textF enter whatever you want to do - I just put in a message to test it was working.
 
I don't think that will work. I had previously put in a DEBUG.PRINT statement in the various event properties and the print statements were never executed when FORMB closed. (the CURRENT event did execute occassionally, but this is unreliable). But its worth a try. I've got other work to complete before I can attempt the experiment.

I am thinking of having a textbox on FORMB that holds the name for the calling form. Then when the user presses the CLOSE button on FORMB, FORMA is refreshed through the code on FORMB just before it closes.
 
My guess is that you are opening the second form with "acDialog". This will cause the activate event not to fire, presumably because the first form's code is still running. If that's what you're doing, you can put the process you want to occur after the open form:

DoCmd.OpenForm "FormB", , , , , acDialog
'put what you want to happen here when FormB is closed
 
One solution achieved! I passed the name of FORMA to FORMB. When FORMB is closed FORMA is updated. I have the following code in FORMB which is executed when FORMB is closed.

If Not IsNull(CallingForm.Value) Then Forms![forma].SetFocus
Forms!formb.SetFocus
DoCmd.Close

----------------------------------------------------------------------------
PBALDY: I read your message after developing the above solution. I will have to experiment with what you suggested as it would be cleaner solution since I would not have to pass a value from one form to another. The ideal situation is that the closure of FORMB automatically triggers the update to FORMA.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom