Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running code when form gets focus 1

Status
Not open for further replies.

zevw

MIS
Jul 3, 2001
697
US
My Program is built that it logs into a Main Menu (Startup Form).

From there you click on your selection, and a different form opens.

What I am trying to do is, every time I close a child form (a form that was opened from the main form, the following code should happen).

When I close a child form I run the following code:

Code:
Private Sub Form_Close()

    Forms!Main.SetFocus
    DoCmd.Maximize
    
End Sub

In the Main Form I run this code, but it does not happen.

Code:
Private Sub Form_GotFocus()

    Set mst = CurrentDb.OpenRecordset("SELECT Messages.* From Messages WHERE (((Messages.Read)=False) AND ((Messages.To)='" & Me.UserLogin & "'));")
    If mst.RecordCount > 0 Then
        mst.MoveLast
        If mst.RecordCount = 1 Then
            Me.CurrMsg.Caption = mst.RecordCount & " New" & vbCrLf & "Message"
        Else
            Me.CurrMsg.Caption = mst.RecordCount & "  New" & vbCrLf & "Messages"
        End If
    End If
    mst.Close

after reading the OnGotFocus Help, I understand that the only time this will work is, if all my controls in the main form are disabled.

How can I get the GotFocus Event Procedure to work, when I have enabled controls on the Main Form. Is there another way to do this?

Thanks in advance for you help!!
 
Have you tried the Activate event ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top