• Can’t move focus error (A2000)

    Author
    Topic
    #389645

    On one of my edit forms I have a combo box called EdSpID to select a certain financial source plus a text box EdSpAmount to record the amount. The idea is that if the user selects EdSpID=0, i.e. not relevant, EdSpAmount is disabled and if EdSpID>0, i.e. a source is selected, EdSpAmount is enabled and the focus moces to it. This is the code:

    Private Sub EdSpID_AfterUpdate()

    If Me!EdSpID = 0 Then
    Me!EdSpAmount = 0
    Me!EdSpAmount.Enabled = False
    DoCmd.GoToControl “btnCancel”
    Else
    Me!EdSpAmount.Enabled = True
    DoCmd.GoToControl “EdSpAmount”
    End If

    End Sub

    When I select a source, EdSpID>0 but it fails on the line DoCmd.GoToControl “EdSpAmount” with a can’t move focus error. I can’t figure out why.

    Viewing 0 reply threads
    Author
    Replies
    • #689066

      Hi David,

      I created a form with a combo box, text box and command button with the names you used, and pasted the code into the AfterUpdate event of the combo box. It works as intended, so there must be something else interfering.

      – Is EdSpAmount visible?
      – Do you have other code that could interfere, in particular On Exit, On Enter, On Lost Focus or On Got Focus event code for one of these controls?

      • #689093

        Hi Hans

        EdSpAmount is visible and I can even see it change from disabled to enabled before the error message appears. EdSpAmount has an exit event that checks if it is zero and resets EdSpID to 0 if it is.

        There are 2 identical pairs of controls on this form and both show the same error. There is another pair with almost identical code which works correctly. Checking its code I found I had used Me!controlname.SetFocus instead of DoCmd. I changed the EdSpID code accordingly and it still bombs out.

        I’ll have another look at all my code tomorrow in case I’m missing something obvious.

    Viewing 0 reply threads
    Reply To: Can’t move focus error (A2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: