Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2005

Tip: Looking for answers? Try searching our database.

On Got Focus?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff M - 31 Mar 2005 16:00 GMT
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
Ken Snell [MVP] - 31 Mar 2005 17:30 GMT
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.

Signature

       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
[quoted text clipped - 12 lines]
>
> End Sub
Jeff M - 31 Mar 2005 18:03 GMT
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
[quoted text clipped - 22 lines]
>
>.
Ken Snell [MVP] - 31 Mar 2005 19:29 GMT
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

Signature

       Ken Snell
<MS ACCESS MVP>

> Ken,
> Here is the code that initiates the Error Message
[quoted text clipped - 83 lines]
>>
>>.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.