Ensure A Form Receives Focus

B

Bob Barnes

I'm returning from another Form to the Form "Opening" w/ code
in the "Parts" Form...

Private Sub Form_Close()
DoCmd.OpenForm "Opening", acNormal, , , , acWindowNormal
End Sub

Even Form_Load in the "opening" Form includes Field1.SetFocus.

The Form's Titlebar remains Dimmed until a Mouse Click.

Ideas?

TIA - Bob
 
J

John W. Vinson

I'm returning from another Form to the Form "Opening" w/ code
in the "Parts" Form...

Private Sub Form_Close()
DoCmd.OpenForm "Opening", acNormal, , , , acWindowNormal
End Sub

Even Form_Load in the "opening" Form includes Field1.SetFocus.

The Form's Titlebar remains Dimmed until a Mouse Click.

Ideas?

TIA - Bob

Try setting focus in two steps: first to the Form, *then* to the control:

Forms!Opening.SetFocus
Forms!Opening!Field1.SetFocus
 
B

Bob Barnes

John - It DIDN'T work...I tried it w/ Form_Activate, Form_Load & Form_Open.

It is an Unbound Form.

Interesting...from the "Parts" Form...
DoCmd.OpenForm "Opening",,,,,acDialog --> WILL SetFocus.

However, navigating back-&-forth (w/ the acDialog) between the 2 Forms can
leave the Database Container being the only thing on the Screen.

Other thoughts please. Thank you - Bob
 
J

John W. Vinson

John - It DIDN'T work...I tried it w/ Form_Activate, Form_Load & Form_Open.

It is an Unbound Form.

Interesting...from the "Parts" Form...
DoCmd.OpenForm "Opening",,,,,acDialog --> WILL SetFocus.

However, navigating back-&-forth (w/ the acDialog) between the 2 Forms can
leave the Database Container being the only thing on the Screen.

Other thoughts please. Thank you - Bob

One thing to bear in mind is that if you have an OpenForm with acDialog set,
the code will STOP at that line (passing control to the form you're opening);
it will only resume execution when the called form is either closed or its
Visible property is set to No.

I really have no idea what you're doing... could you post the actual code?
 
B

Bob Barnes

From "Opening" ----------------------------------------- Dn
Private Sub Label8_Click()
Dim Z As Database, RS As DAO.Recordset, Q$
On Error GoTo EH
Set Z = CurrentDb
'Are times recorded by Parts or Machines?
Q = "SELECT DISTINCTROW OpTmCalcStyle " _
& "From [T:process/Group XRef Junction]" _
& " WHERE (ProcessID = " & List2.Column(0) & " AND" _
& " GroupID = " & List5.Column(0) & ");"
gDateSel = txtDate: gShiftSel = TheShift
gDayWeek = DayOfWeek: gIDGroup = List5.Column(0)
gGroupSel = List5.Column(1): gIIDProc = List2.Column(0)
gProcSel = List2.Column(1)
Set RS = Z.OpenRecordset(Q, dbOpenSnapshot)
With RS
gEntryForm = !OpTmCalcStyle
.Close: Set RS = Nothing: Z.Close: Set Z = Nothing
End With
Select Case gEntryForm
Case 1 'Parts-based
Screen.MousePointer = 11: Me.Repaint: cmdExit.Enabled = False
List2.SetFocus: txtDate.Enabled = False
cmdCal.Enabled = False: TheShift.Enabled = False
cmdClear.Enabled = False: DayOfWeek.Enabled = False
cmdLogOn.Enabled = False: Label8.Visible = False: cmd_GoGo.Visible = False
lblWait.Visible = True
'2/11/10 - 2004 Archive Allen Browne - DoCmd.Close acForm, Me.Name (seems
to run faster)
DoCmd.OpenForm "Parts": DoCmd.Close acForm, Me.Name 'DoCmd.Close acForm,
"Opening"
Case 2
'Machine-based Entry
Screen.MousePointer = 11: Me.Repaint: cmdExit.Enabled = False
List2.SetFocus: txtDate.Enabled = False
cmdCal.Enabled = False: TheShift.Enabled = False
cmdClear.Enabled = False: DayOfWeek.Enabled = False
cmdLogOn.Enabled = False: Label8.Visible = False: cmd_GoGo.Visible = False
lblWait.Visible = True
'2/11/10 - 2004 Archive Allen Browne - DoCmd.Close acForm, Me.Name (seems
to run faster)
DoCmd.OpenForm "Machines": DoCmd.Close acForm, Me.Name 'DoCmd.Close
acForm, "Opening"
Exit Sub
End Select
EH1:
If Not RS Is Nothing Then RS.Close: Set RS = Nothing
If Not Z Is Nothing Then Z.Close: Set Z = Nothing
Screen.MousePointer = 1: Exit Sub
EH:
Select Case Err
Case 2164
List2.SetFocus: Resume EH1
Case Else
MsgBox Err.Number & " " & Err.Description: Resume EH1
End Select
End Sub
From "Opening" ----------------------------------------- Up

From the "Parts" Form... ---------------------------------- Dn
Private Sub cmdClose_Click()
Dim Z As Database, RS As DAO.Recordset, Q$, M$
On Error GoTo AAA1
b_FmPart = True: Call P_Pop_Open
FmDatePart = TheDate: aPartShift = PartShift
'2/11/10 - 2004 Archive Allen Browne - DoCmd.Close acForm, Me.Name (seems to
run faster)
'DoCmd.OpenForm "Opening": DoCmd.Close acForm, Me.Name 'DoCmd.Close acForm,
"Parts"
DoCmd.Close acForm, Me.Name
AAA2:
Screen.MousePointer = 1: Exit Sub
AAA1:
Select Case Err
Case Else
MsgBox "Error Number " & Err.Number & " " & Err.Description
Resume AAA2
End Select
End Sub

Private Sub Form_Close()
DoCmd.OpenForm "Opening", acNormal, , , , acWindowNormal
End Sub

Private Sub Form_Open(Cancel As Integer)
Forms!Opening.SetFocus: Forms!Opening!ForSafe.SetFocus: Me.Repaint:
DoCmd.Maximize
End Sub
From the "Parts" Form... ---------------------------------- Up
 
B

Bob Barnes

There are 3 Forms = Opening, Parts, & Machines.

The "Opening" Form selects one of several Manufacturing Processes for Data
Entry.

We only want one Form Open at any given time. Everything works
great...except returning to the "Opening" Form requires Clicking the Form.

JimBurke via AccessMonster.com said:
Why are you closing the form when you go to form 'Parts', then re-opening it
again when 'Parts' is closed? I would think you would just want to leave the
form open. When 'Parts' is closed you should end up back at your original
form. Is there a specific reason you set it up this way?

Bob said:
From "Opening" ----------------------------------------- Dn
Private Sub Label8_Click()
Dim Z As Database, RS As DAO.Recordset, Q$
On Error GoTo EH
Set Z = CurrentDb
'Are times recorded by Parts or Machines?
Q = "SELECT DISTINCTROW OpTmCalcStyle " _
& "From [T:process/Group XRef Junction]" _
& " WHERE (ProcessID = " & List2.Column(0) & " AND" _
& " GroupID = " & List5.Column(0) & ");"
gDateSel = txtDate: gShiftSel = TheShift
gDayWeek = DayOfWeek: gIDGroup = List5.Column(0)
gGroupSel = List5.Column(1): gIIDProc = List2.Column(0)
gProcSel = List2.Column(1)
Set RS = Z.OpenRecordset(Q, dbOpenSnapshot)
With RS
gEntryForm = !OpTmCalcStyle
.Close: Set RS = Nothing: Z.Close: Set Z = Nothing
End With
Select Case gEntryForm
Case 1 'Parts-based
Screen.MousePointer = 11: Me.Repaint: cmdExit.Enabled = False
List2.SetFocus: txtDate.Enabled = False
cmdCal.Enabled = False: TheShift.Enabled = False
cmdClear.Enabled = False: DayOfWeek.Enabled = False
cmdLogOn.Enabled = False: Label8.Visible = False: cmd_GoGo.Visible = False
lblWait.Visible = True
'2/11/10 - 2004 Archive Allen Browne - DoCmd.Close acForm, Me.Name (seems
to run faster)
DoCmd.OpenForm "Parts": DoCmd.Close acForm, Me.Name 'DoCmd.Close acForm,
"Opening"
Case 2
'Machine-based Entry
Screen.MousePointer = 11: Me.Repaint: cmdExit.Enabled = False
List2.SetFocus: txtDate.Enabled = False
cmdCal.Enabled = False: TheShift.Enabled = False
cmdClear.Enabled = False: DayOfWeek.Enabled = False
cmdLogOn.Enabled = False: Label8.Visible = False: cmd_GoGo.Visible = False
lblWait.Visible = True
'2/11/10 - 2004 Archive Allen Browne - DoCmd.Close acForm, Me.Name (seems
to run faster)
DoCmd.OpenForm "Machines": DoCmd.Close acForm, Me.Name 'DoCmd.Close
acForm, "Opening"
Exit Sub
End Select
EH1:
If Not RS Is Nothing Then RS.Close: Set RS = Nothing
If Not Z Is Nothing Then Z.Close: Set Z = Nothing
Screen.MousePointer = 1: Exit Sub
EH:
Select Case Err
Case 2164
List2.SetFocus: Resume EH1
Case Else
MsgBox Err.Number & " " & Err.Description: Resume EH1
End Select
End Sub
From "Opening" ----------------------------------------- Up

From the "Parts" Form... ---------------------------------- Dn
Private Sub cmdClose_Click()
Dim Z As Database, RS As DAO.Recordset, Q$, M$
On Error GoTo AAA1
b_FmPart = True: Call P_Pop_Open
FmDatePart = TheDate: aPartShift = PartShift
'2/11/10 - 2004 Archive Allen Browne - DoCmd.Close acForm, Me.Name (seems to
run faster)
'DoCmd.OpenForm "Opening": DoCmd.Close acForm, Me.Name 'DoCmd.Close acForm,
"Parts"
DoCmd.Close acForm, Me.Name
AAA2:
Screen.MousePointer = 1: Exit Sub
AAA1:
Select Case Err
Case Else
MsgBox "Error Number " & Err.Number & " " & Err.Description
Resume AAA2
End Select
End Sub

Private Sub Form_Close()
DoCmd.OpenForm "Opening", acNormal, , , , acWindowNormal
End Sub

Private Sub Form_Open(Cancel As Integer)
Forms!Opening.SetFocus: Forms!Opening!ForSafe.SetFocus: Me.Repaint:
DoCmd.Maximize
End Sub
From the "Parts" Form... ---------------------------------- Up
John - It DIDN'T work...I tried it w/ Form_Activate, Form_Load & Form_Open.
[quoted text clipped - 14 lines]
I really have no idea what you're doing... could you post the actual code?

--
Jim Burke



.
 
B

Bob Barnes

I've been offline 2+ days, so am answering late.

I could make "Opening" Visible = False.

I've written code for years where only one Form is open. It's always
worked, except for now where the Form doesn't get Focus. Gotta be a reason
why...was hoping someone knew why.

Thank you - Bob

JimBurke via AccessMonster.com said:
Do you always end up back at the 'Opening' form? If so there is no need to
close it. What is the reason for only wanting one form open? Is there some
reason why Opening can't be open when you go to one of the other forms?

Bob said:
There are 3 Forms = Opening, Parts, & Machines.

The "Opening" Form selects one of several Manufacturing Processes for Data
Entry.

We only want one Form Open at any given time. Everything works
great...except returning to the "Opening" Form requires Clicking the Form.
Why are you closing the form when you go to form 'Parts', then re-opening it
again when 'Parts' is closed? I would think you would just want to leave the
[quoted text clipped - 96 lines]
I really have no idea what you're doing... could you post the actual code?

--
Jim Burke

Message posted via AccessMonster.com


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top