Method 'Items' of object "Forms" failed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • svdoerga
    New Member
    • Jul 2008
    • 18

    #1

    Method 'Items' of object "Forms" failed

    I found a post with the same error here.
    I'm getting the same error. This code is run in a button click event:
    Code:
    ...........
    DoCmd.OpenForm CurTabViewName, acNormal
    With Forms(CurTabViewName) 
    ...........
    At the "With" statement I get the error. Weird thing is this code had been working fine a long time. I've been searching the net and haven't been able to find the solution yet. Does anyone know a solution?

    Only possibility I found out (from the above linked post) is that maybe it has to do with timing. I can imagine that the form is not completely ready when the "with" statement executes. Is there any way to tell access to wait until the form is completely loaded before executing the "with" statement?
  • hyperpau
    Recognized Expert New Member
    • Jun 2007
    • 184

    #2
    have you tried putting a refresh, repaint, or recalc method in betweene these codes?

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Access executes Command2 without waiting for Command1 to finish executing, which can, indeed, cause timing problems. In this case, my guess is that the form hasn't finished loading/opening when the next line of code tries to reference it.

      Refresh, repaint, or recalc is going to do nothing to correct this. What does frequently help is to place the command DoEvents between two commands.
      DoEvents basically sends control from Access to Windows to allow Command1 to finish before returning control to Access to execute Command2.

      Welcome to Bytes!

      Linq ;0)>

      Comment

      • hyperpau
        Recognized Expert New Member
        • Jun 2007
        • 184

        #4
        Wow. That's new for me! :)

        Thanks Missingling.


        Originally posted by missinglinq
        Access executes Command2 without waiting for Command1 to finish executing, which can, indeed, cause timing problems. In this case, my guess is that the form hasn't finished loading/opening when the next line of code tries to reference it.

        Refresh, repaint, or recalc is going to do nothing to correct this. What does frequently help is to place the command DoEvents between two commands.
        DoEvents basically sends control from Access to Windows to allow Command1 to finish before returning control to Access to execute Command2.

        Welcome to Bytes!

        Linq ;0)>

        Comment

        Working...