On Got Focus?

  • Thread starter Thread starter Jeff M
  • Start date Start date
J

Jeff M

I have a form that is used to lookup a specific record in
the underlying table based on user input in the Text1
field. When user input does not match any record on the
table, an error window pops up detailing the error, and is
closed when the user clicks the OK button.

How can I make it so that when the error window closes,
that the tab control automatically goes back to the Text1
field? I have tried to set the On Got Focus property as
follows, but it doesn't work:

Private Sub Form_GotFocus()

DoCmd.GoToControl , "[Text1]"

End Sub
 
A form does not get focus unless there is no control on the form that can
receive the focus. Thus, based on your description, it would appear that the
code never runs because the form doesn't get focus.

Post all the code that you're using to pop up the error message. We should
be able to add some code there to accomplish your purpose.
 
Ken,
Here is the code that initiates the Error Message
Form "IDDoesNotExist":

Private Sub FindCustID_Click()
On Error GoTo Err_FindCustID_Click

Dim stDocName As String
Dim count As Variant
Dim stLinkCriteria As String

stDocName = "CustDetailsTableInputFormUPDATE"
count = DCount("[CUST ID]", "CustDetailsTable", "[CUST
ID]=" & Me![Text1])
stLinkCriteria = "[CUST ID]=" & Me![Text1]

If count = 1 Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Maximize
DoCmd.Close acForm, "Switchboard"
DoCmd.Close acForm, "FindCustID"
ElseIf count = 0 Then
DoCmd.OpenForm "IDDoesNotExist"
End If

Exit_FindCustID_Click:
Exit Sub

Err_FindCustID_Click:
MsgBox Err.Description
Resume Exit_FindCustID_Click

End Sub


Here is the code for the Error Message
Form "IDDoesNotExist":

Private Sub OK_Click()
On Error GoTo Err_OK_Click

DoCmd.Close

Exit_OK_Click:
Exit Sub

Err_OK_Click:
MsgBox Err.Description
Resume Exit_OK_Click

End Sub

Thanks!!!
Jeff M
-----Original Message-----
A form does not get focus unless there is no control on the form that can
receive the focus. Thus, based on your description, it would appear that the
code never runs because the form doesn't get focus.

Post all the code that you're using to pop up the error message. We should
be able to add some code there to accomplish your purpose.

--

Ken Snell
<MS ACCESS MVP>


I have a form that is used to lookup a specific record in
the underlying table based on user input in the Text1
field. When user input does not match any record on the
table, an error window pops up detailing the error, and is
closed when the user clicks the OK button.

How can I make it so that when the error window closes,
that the tab control automatically goes back to the Text1
field? I have tried to set the On Got Focus property as
follows, but it doesn't work:

Private Sub Form_GotFocus()

DoCmd.GoToControl , "[Text1]"

End Sub


.
 
Just need an extra step in the If block to reset the focus to the textbox:

If count = 1 Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Maximize
DoCmd.Close acForm, "Switchboard"
DoCmd.Close acForm, "FindCustID"
ElseIf count = 0 Then
DoCmd.OpenForm "IDDoesNotExist"
Me.Text1.SetFocus
End If


--

Ken Snell
<MS ACCESS MVP>


Jeff M said:
Ken,
Here is the code that initiates the Error Message
Form "IDDoesNotExist":

Private Sub FindCustID_Click()
On Error GoTo Err_FindCustID_Click

Dim stDocName As String
Dim count As Variant
Dim stLinkCriteria As String

stDocName = "CustDetailsTableInputFormUPDATE"
count = DCount("[CUST ID]", "CustDetailsTable", "[CUST
ID]=" & Me![Text1])
stLinkCriteria = "[CUST ID]=" & Me![Text1]

If count = 1 Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Maximize
DoCmd.Close acForm, "Switchboard"
DoCmd.Close acForm, "FindCustID"
ElseIf count = 0 Then
DoCmd.OpenForm "IDDoesNotExist"
End If

Exit_FindCustID_Click:
Exit Sub

Err_FindCustID_Click:
MsgBox Err.Description
Resume Exit_FindCustID_Click

End Sub


Here is the code for the Error Message
Form "IDDoesNotExist":

Private Sub OK_Click()
On Error GoTo Err_OK_Click

DoCmd.Close

Exit_OK_Click:
Exit Sub

Err_OK_Click:
MsgBox Err.Description
Resume Exit_OK_Click

End Sub

Thanks!!!
Jeff M
-----Original Message-----
A form does not get focus unless there is no control on the form that can
receive the focus. Thus, based on your description, it would appear that the
code never runs because the form doesn't get focus.

Post all the code that you're using to pop up the error message. We should
be able to add some code there to accomplish your purpose.

--

Ken Snell
<MS ACCESS MVP>


I have a form that is used to lookup a specific record in
the underlying table based on user input in the Text1
field. When user input does not match any record on the
table, an error window pops up detailing the error, and is
closed when the user clicks the OK button.

How can I make it so that when the error window closes,
that the tab control automatically goes back to the Text1
field? I have tried to set the On Got Focus property as
follows, but it doesn't work:

Private Sub Form_GotFocus()

DoCmd.GoToControl , "[Text1]"

End Sub


.
 
Back
Top