none
Famous error 2110 is back :) RRS feed

  • Question

  • Good morning everyone,

    I have a form named "Détails commandeBT] that has a subform named "sbfOrderDetails" on which a field name is "ProductID"

    I want to set the focus on that field, so in order to do that, I have created a new field on the form named "TrouverNouvelleCommande" and on the GotFocus event of that field, I have this code:

    Private Sub TrouverNouvelleCommande_GotFocus()
    On Error GoTo Change_Err
    
    Forms![Détails commandeBT].SetFocus
    DoCmd.GoToRecord , "", acLast
    Me.sbfOrderDetails.Visible = True
    DoCmd.GoToControl "sbfOrderDetails"
    DoCmd.GoToControl "Product ID"
    DoCmd.GoToRecord , , acNewRec
    
    Exit_Here:
    Exit Sub
    
    Change_Err:
        If Err = "2110" Then
            Resume Exit_Here
        End If
    End Sub

    When I give the focus directly to that field, it works perfectly, however, if I try to give the focus from another form, then I received a 2110 error.

    That 2110 error comes from the form "frmSynthèse commande pour plan de salle" on the From_close event:

    Private Sub Form_Close()
             Forms![Détails commandeBT].SetFocus
             DoCmd.GoToControl "TrouverNouvelleCommande"
    End Sub
     

    That does almost the samething, however, I receive an error 2110 that tells me that the control "TrouverNouvelleCommande" could not be activated, but it does because the focus goes on Forms![Détails commandeBT].[sbfOrderDetails].form.ProductID It does exactly what the GotFocus event code on the field "TrouverNouvelleCommande" says.

    So why do I receive that 2110 error?

    I have place an image on OneDrive, so please click on the link below:

    https://onedrive.live.com/redir?resid=F7190044A52FAE85!680&authkey=!ABsib92NK_1h8SE&v=3&ithint=photo%2cjpg

    Thanks

    Claude from Quebec


    Claude Larocque

    Saturday, July 18, 2015 10:44 AM

All replies

  • Since 2007, Access is quirky about form focus when another form closes.  Though the next form may look like it has focus because it is in the forefront, it isn't necessarily the active form, even if you have specifically assigned focus.  So when you use the GotoControl method, Access doesn't recognize the control your are attempting to move to.

    Let me ask, is the control "TrouverNouvelleCommande" on the sub-form "sbfOrderDetails", or is it part of the main form?

    Let me ask this too, is the form "frmSynthèse commande pour plan de sale" opened from the form "Détails commandeBT?"

    If that is the case, then instead of trying to manage focus from the closing form, handle it when control is returned to the procedure that opened the form.  You would do this by opening the form "frmSynthèse commande pour plan de sale" as a modal dialog. 

    Private Sub cmdOpenMyForm_Click()
    
        On Error GoTo Err_Process
        
        Dim strFormName As String
        
        strFormName = "frmSynthèse commande pour plan de sale"
        
        DoCmd.OpenForm strFormName, acNormal, , , , acDialog
        
        'Assuming the command button to open the form [frmSynthèse commande pour plan de sale]
        'is on the main form, then attempt to set focus back to the form,
        'then the command button, then move to the last record.  We have to 
    'ensure that the main form has focus before attempting to execute
    'the GotoRecord method.
    Me.SetFocus Me.cmdOpenMyForm.SetFocus DoCmd.GoToRecord , "", acLast 'Make the subform visible then navigate to it, then the specific control, then move 'to a new record. Me.sbfOrderDetails.Visible = True Me.sbfOrderDetails.SetFocus Me.sbfOrderDetails.Form!ProductID.SetFocus DoCmd.GoToRecord , , acNewRec Exit_Process: Exit Sub Err_Process: 'Your error handler Resume Exit_Process End Sub





    • Edited by RunningManHD Saturday, July 18, 2015 3:15 PM
    • Proposed as answer by ryguy72 Saturday, July 18, 2015 4:13 PM
    Saturday, July 18, 2015 2:25 PM
  • Thanks for your answer,

    More details:

    control "TrouverNouvelleCommande" is on the main form "Détails commandeBT", however, the form "frmSynthèse commande pour plan de salle" open from another form named "PlanDeSalle La Bagelière".

    To summarize, the user click on the button named "NouvelleCommandePièces_Étiquette" that opens the form on image 2 "PlanDeSalle La Bagelière" then when the user clicks on a specific table, then the form "frmSynthèse commande pour plan de salle" open and on that form the user clicks on the button "AjouterUneCommande" to create a new order if needed.

    I will use your code with the acDialog to open the first form modal and play a little with the code, I will come back very soon...

    Thanks

    Claude


    Claude Larocque

    Saturday, July 18, 2015 4:44 PM
  • Please go to these link, I revamp the 3 images with more details, I am sure this is a small error in the code, but the error 2110 is not there anymore, it does not have any error but the code does not do what expected.

    Thanks!

    Claude

    Form: Détails commandeBT:

    https://onedrive.live.com/redir?resid=F7190044A52FAE85!685&authkey=!APzD81P9B9L6nKw&v=3&ithint=photo%2cjpg

    Form: PlanDeSalle La Bagelière:

    https://onedrive.live.com/redir?resid=F7190044A52FAE85!682&authkey=!APll3pAgpfzPkBo&v=3&ithint=photo%2cjpg

    Form: frmSynthèseCommande pour plan de salle:

    https://onedrive.live.com/redir?resid=F7190044A52FAE85!684&authkey=!AIHNWmXQAnmbwUY&v=3&ithint=photo%2cjpg


    Claude Larocque


    • Edited by Claude Larocque Saturday, July 18, 2015 7:28 PM Link didn't work
    Saturday, July 18, 2015 7:24 PM
  • Claude,

    For what you are doing, there is no need to open your first form as a dialog.  That was only a solution if the one form you are using to manipulate the main form was being opened from the main form.

    What you have to understand is that the methods of DoCmd, such as GotoControl and GotoRecord, require that the target form be the active form.  The same goes for a sub-form, it must have the focus to utilize those methods.  As far as manipulating focus, rather than using the GotoControl method, you can manage focus explicitly using the SetFocus method of the target form and/or control.

    After looking over your images and some of the code, I'm not all certain that your workflow and procedures are most appropriate or efficient.  You might want to give this some more thought. 

    I do wish you luck and I hope this will help you achieve your goal.

    Regards,


    Saturday, July 18, 2015 11:27 PM
  • Hi RunningManHD,

    First you are probably right, I will need to analyze the workflow one of these days, however, I have more than 120 customers that are using my software and I have almost no bugs :)

    I wrote almost because as you probably know these users bugs are hard to detect...

    I will address this problem another way because I noticed that when I am on the main form "Détails commandeBT" and I click in a field named "TrouverNouvelleCommande", everything is working... but only once, after that if I click in that field (that receive the focus) nothing is going on, however, if I close the main form and open it back, then it works only once and so on.

    So my thinking about that is that in the code below, something is missing to release something after the code ran:

    DoCmd.GoToRecord , "", acLast
    Forms![Détails commandeBT].SetFocus
    Me.sbfOrderDetails.Visible = True
    DoCmd.GoToControl "sbfOrderDetails"
    DoCmd.GoToControl "Product ID"
    DoCmd.GoToRecord , , acNewRec

    May be something is missing there?


    Claude Larocque

    Sunday, July 19, 2015 1:03 PM
  • Hi Claude Larocque,

    Have you fixed this issue now?

    According to the description, you want to set the focus for the control on the subform from the close event in another form.

    As far as I know, we can set the focus for the control directly instead of set the focus for the control on the main form then set the focus based on the event for that control.

    Here is the code that set focus to the control('Text4') on the subform('Form1') from another form:

    'Book1 is main form

    Private Sub Form_Close()

    Forms![Book1].SetFocus Forms![Book1].Form1.SetFocus DoCmd.GoToControl "Text4"

    End Sub


    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, July 21, 2015 5:52 AM
    Moderator
  • Thanks for your time,

    but no it is not solved, it seems easy the setfocus and gotocontrol, but nothing works.

    hope someone will find whats wrong

    Thanks


    Claude Larocque

    Thursday, July 30, 2015 10:22 AM
  • Claude,

    If you are willing to post your DB to OneDrive, I will be happy to take a look at it to see if I can't solve your problem.

    Thursday, July 30, 2015 2:23 PM
  • My DB is more than 300 Mb and this is my software that I sell to customers, I can't put it available for anyone with the code. Hope you understand.

    Claude


    Claude Larocque

    Friday, July 31, 2015 9:20 AM
  • No worries...
    Friday, July 31, 2015 12:41 PM