By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,207 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,207 IT Pros & Developers. It's quick & easy.

Opened Form is not getting Focus

P: n/a
Hi.

I am opening a form (frmUserSettings) just before (or so I thought) the
Main Menu form (frmMainMenu) is opening but it's not getting the focus.
It gets "painted" and then the Main Menu gets "painted" right on top of
the frmUserSettings. Since the Main Menu form is smaller (in width and
height) I can click on frmUserSettings and get it to the front (focus).
But is there a way to do this programmatically? Can you help me?

Here is some of the code behind the forms...

FormOpen routine in frmMainMenu:

Private Sub Form_Load()
On Error GoTo Err_Form_Load

Dim strDisplaySettings As String

'Find the value of User Variable to check or uncheck the
ckUserSettings ckbox on the form
'NOTE: I have BeforeUpdate and AfterUpdate routines for the
ckUserSettings ckbox which will cause an update to the User Variable in
tblUserSettings
strDisplaySettings = DLookup("[uval]", "[tblUserSettings]", "[uvar]
= 'U_DisplayUserSettings'")
Me.AllowEdits = True
If strDisplaySettings = "Y" Then
Me!ckUserSettings = True
Call DisplayUserSettings
Else
Me!ckUserSettings = False
End If
Me.AllowEdits = False

Exit_Form_Load:
Exit Sub

Err_Form_Load:
Call ShowError("frmMainMenu", "Form_Load", Err.Number,
Err.Description)
Resume Exit_Form_Load

End Sub
*================================================= *

DisplayUserSettings() routine in frmMainMenu that is called by
Form_Load():

Public Sub DisplayUserSettings()
On Error GoTo Err_DisplayUserSettings

Dim strMsg As String
Dim intAnswer As Integer
Dim db As DAO.Database
Dim rsUS As DAO.Recordset
Dim ix As Integer
Dim intVarCount As Integer

strMsg = "Current USER VARIABLE values are: " & vbCrLf & vbCrLf
Set db = CurrentDb
Set rsUS = db.OpenRecordset("tblUserSettings")
If rsUS.EOF Then GoTo Exit_DisplayUserSettings
rsUS.MoveFirst

Do While Not rsUS.EOF
strMsg = strMsg & _
"Variable: " & rsUS!uvar & vbCrLf & _
"Value: " & rsUS!uval & vbCrLf & _
"Description: " & rsUS!udesc & vbCrLf & vbCrLf
rsUS.MoveNext
Loop

strMsg = strMsg & vbCrLf & "=====================================" &
vbCrLf & vbCrLf & _
"Do you wish to change any User Variable Settings? (Yes or
No?)"

intAnswer = MsgBox(strMsg, vbQuestion + vbYesNo, "User Settings")
'If intAnswer = vbYes Then DoCmd.RunMacro "NotAvailable"
If intAnswer = vbYes Then DoCmd.OpenForm "frmUserSettings", acNormal

Exit_DisplayUserSettings:
rsUS.Close
Set rsUS = Nothing
Set db = Nothing
Exit Sub

Err_DisplayUserSettings:
Call ShowError("frmMainMenu", "DisplayUserSettings", Err.Number,
Err.Description)
Resume Exit_DisplayUserSettings

End Sub


Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Unless another form is opened modally or as a popup, you can bring a form
forward by setting focus to it, e.g.:
Forms("frmUserSettings").SetFocus

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Susan Bricker" <sl*****@verizon.net> wrote in message
news:RG**************@news.uswest.net...
Hi.

I am opening a form (frmUserSettings) just before (or so I thought) the
Main Menu form (frmMainMenu) is opening but it's not getting the focus.
It gets "painted" and then the Main Menu gets "painted" right on top of
the frmUserSettings. Since the Main Menu form is smaller (in width and
height) I can click on frmUserSettings and get it to the front (focus).
But is there a way to do this programmatically? Can you help me?

Here is some of the code behind the forms...

FormOpen routine in frmMainMenu:

Private Sub Form_Load()
On Error GoTo Err_Form_Load

Dim strDisplaySettings As String

'Find the value of User Variable to check or uncheck the
ckUserSettings ckbox on the form
'NOTE: I have BeforeUpdate and AfterUpdate routines for the
ckUserSettings ckbox which will cause an update to the User Variable in
tblUserSettings
strDisplaySettings = DLookup("[uval]", "[tblUserSettings]", "[uvar]
= 'U_DisplayUserSettings'")
Me.AllowEdits = True
If strDisplaySettings = "Y" Then
Me!ckUserSettings = True
Call DisplayUserSettings
Else
Me!ckUserSettings = False
End If
Me.AllowEdits = False

Exit_Form_Load:
Exit Sub

Err_Form_Load:
Call ShowError("frmMainMenu", "Form_Load", Err.Number,
Err.Description)
Resume Exit_Form_Load

End Sub
*================================================= *

DisplayUserSettings() routine in frmMainMenu that is called by
Form_Load():

Public Sub DisplayUserSettings()
On Error GoTo Err_DisplayUserSettings

Dim strMsg As String
Dim intAnswer As Integer
Dim db As DAO.Database
Dim rsUS As DAO.Recordset
Dim ix As Integer
Dim intVarCount As Integer

strMsg = "Current USER VARIABLE values are: " & vbCrLf & vbCrLf
Set db = CurrentDb
Set rsUS = db.OpenRecordset("tblUserSettings")
If rsUS.EOF Then GoTo Exit_DisplayUserSettings
rsUS.MoveFirst

Do While Not rsUS.EOF
strMsg = strMsg & _
"Variable: " & rsUS!uvar & vbCrLf & _
"Value: " & rsUS!uval & vbCrLf & _
"Description: " & rsUS!udesc & vbCrLf & vbCrLf
rsUS.MoveNext
Loop

strMsg = strMsg & vbCrLf & "=====================================" &
vbCrLf & vbCrLf & _
"Do you wish to change any User Variable Settings? (Yes or
No?)"

intAnswer = MsgBox(strMsg, vbQuestion + vbYesNo, "User Settings")
'If intAnswer = vbYes Then DoCmd.RunMacro "NotAvailable"
If intAnswer = vbYes Then DoCmd.OpenForm "frmUserSettings", acNormal

Exit_DisplayUserSettings:
rsUS.Close
Set rsUS = Nothing
Set db = Nothing
Exit Sub

Err_DisplayUserSettings:
Call ShowError("frmMainMenu", "DisplayUserSettings", Err.Number,
Err.Description)
Resume Exit_DisplayUserSettings

End Sub

Nov 13 '05 #2

P: n/a
Allen,

Thank you for the reply. I'll give it a try. I think I still have a
problem, though, because the 2nd form (frmUserSettings) is being opened
up within the Form_Load event of frmMainMenu. Form_Load seems to be
kicked off somewhere in the middle of Form_Open event of frmMainMenu.
So, after frmUserSettings is opened (via the DoCmd) frmMenu gets control
back and continues processing Form_Load and Form_Open. I'm assuming
that's why frmMainMenu has the focus.

So, when I finally get back to the end of Form_Open in frmMainMenu, can
I test to see if frmUserSettings has been opened (It won't always be
opened) and if it is, SetFocus to it at that point? How would I do
that?

I can't find the answer in this Forum. And, guess what, I don't have
online help for MS/Access here at work. I've been trying to get the PC
support folks here at work to correct the problem, but they are stumped.
(I ususlly get alot of my help info when I develop Access "stuff" at
home).

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #3

P: n/a
Alx
Susan Bricker wrote:
So, when I finally get back to the end of Form_Open in frmMainMenu, can
I test to see if frmUserSettings has been opened (It won't always be
opened) and if it is, SetFocus to it at that point? How would I do
that?


FormIsOpen = SysCmd(acSysCmdGetObjectState, acForm, "frmUserSettings")_
And acObjStateOpen

Alx

P.S. - Sorry, Allen, but this is something I know, which doesn't happen
often! :))))
Nov 13 '05 #4

P: n/a
Alx,
Thanks. That does work, sort of!!! Just before leaving Form_Open event
of frmMainMenu I put ...

blnFormIsOpen = SysCmd(acSysCmdGetObjectState,
acForm, "frmUserSettings") _
And acObjStateOpen

If blnFormIsOpen Then
Forms("frmUserSettings").SetFocus
End If

However, I still get the same result; frmUserSettings appears behind the
frmMainMenu. I traced the routine and actually the screen flicker when
the .SetFocus is executed. So, I assume that it is working. It's just
that the Main Menu is getting control back. While in trace it doesn't
do anything after the .SetFocus except the Exit Sub in Form_Open of
frmMainMenu.

Any ideas?

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #5

P: n/a
Alx
I lost your first posts, so I'm not really in the picture... do you
really need Form_Open to continue its processing after opening
frmUserSettings? Can't you open frmUserSettings as modal?

Alx
Nov 13 '05 #6

P: n/a
Alx,

Modal is set to 'yes' for frmUserSettings. As for Form_Open continuing
to process ... I am at a loss as to whether I need it to continue
processing.

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #7

P: n/a
Susan Bricker <sl*****@verizon.net> wrote in
news:b5***************@news.uswest.net:
Modal is set to 'yes' for frmUserSettings. As for Form_Open
continuing to process ... I am at a loss as to whether I need it
to continue processing.


I have never found the form properties for modal and popup to be of
much use. When I want a modal form I use the acDialog switch the the
DoCmd.OpenForm command.

Also, I tend to hide the main menu form when I launch a form from
it, and then have the OnClose event of the child forms set the main
menu's .Visible property to True. If it's not visible, it would be
prevented from stealing the focus.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8

P: n/a
David,

THANK YOU, THANK YOU, THANK YOU. I used both of your suggestions and
all is well with my world, now! Thanks, again.

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.