Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't move focus error (A2000)

    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.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can't move focus error (A2000)

    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?

  3. #3
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't move focus error (A2000)

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •