Set focus back to the active form correctly
I have an access app with overlapping tabs, and the home form/switchboard stays 'open' throughout the period of time the app is open. I believe this to be the correct methodology.
With this in mind i use the following code to send an "are you sure message?" to the user if they try to close the database without using the correct controls that are displayed.
Private Sub Form_Unload(Cancel As Integer)
If Me.chkCloseDB = False Then
If MsgBox("Are you sure you want to close the database", vbYesNo, dbNameOf) <> vbYes Then _
Cancel = True
End If
End Sub
Me.chkCloseDB gets set as true if the user presses the 'Close DB' button.
The 开发者_运维知识库problem I have is that if the user has navigated to another form, that is then essentially sitting on top of the switchboard and has focus, if the user tries to close the database and cancels the action i don't know how to get the focus back to the active form.
It appears that the the form that was/is active is sitting on top but it cant be accessed and all controls cant be used. Its as if the switchboard, which is at the bottom of the pile as i see it, has the focus even though you cant see it.
So the question I am asking is how can i re-activate or set focus to the form on top of the pile.
Hope that makes sense! Thanks in advance to anybody who can enlighten me as to what I need to do here to make this work.
Cheers Noel
Resolved: The switchboard/home forms property was set to Modal, even though it didnt have the focus, or could not be seen, it seemed to cause the problem. Set Modal on the forms properties to No and it resolved the issue.
The following code should do the trick. I have used it in the past without problems
Forms!frmYourForm.SetFocus
精彩评论