Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2010

    Unanswered: *error msg* Method 'Item' of object 'Forms' failed

    I get the the following error message when trying to execute the below command " Method 'Item' of object 'Forms' failed "

    Private Sub Command20_Click()

    DoCmd.OpenForm "Form1", acNormal, , , acEdit, acWindowNormal, " "

    [Forms]![Form1]![Text148] = DLookup("[Apt_ID]", "Appointment_Table", "[Apt_ID] = [Forms]![Form2]![List5]")

    DoCmd.Close acForm, "Form2", acSaveYes

    End Sub

    I don't get it because I have a similar command button written with the same code (names switched obviously) for a different form and it works. I'm super confused on it. Is it something else in my DB that is doing this (maybe something already written into the form or something).

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 15
    Try by splitting the offending line to determine what's the cause of the error:

    Private Sub Command20_Click()
    Dim x as Variant
    DoCmd.OpenForm "Form1", acNormal, , , acEdit, acWindowNormal, " "
    x = DLookup("[Apt_ID]", "Appointment_Table", "[Apt_ID] = [Forms]![Form2]![List5]")
    [Forms]![Form1]![Text148] = x
    DoCmd.Close acForm, "Form2", acSaveYes
    End Sub
    I suspect the DLookUp function here (bad name or missing quotes). In my opinion it should be:
    DLookup("[Apt_ID]", "Appointment_Table", "[Apt_ID] = " & [Forms]![Form2]![List5])
    Have a nice day!

  3. #3
    Join Date
    May 2005
    Nevada, USA
    Provided Answers: 6
    Further, what's the point of the DLookup at all? You're looking up the Apt_ID that matches the Apt_ID on Form2. Why not just grab it from Form2?

    Forms![Form1]![Text148] = Forms![Form2]![List5]

  4. #4
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    Access executes code asynchronously, which is to say if you have, in code


    it starts to execute CommandA, and then, without waiting for it to finish, starts executing CommandB, and without waiting for that to finish, starts executing CommandC. If a command is somehow dependent on a prior command finishing before doing it's task this can cause timing problems.

    My guess would be that DLookup(), which is somewhat slow, hasn't finished executing when Form2 is closed. And if you try to reference a control, as you're doing in the DLookup() here, in a closed form, you will pop an error.

    I'd comment out the line

    DoCmd.Close acForm, "Form2", acSaveYes

    and see if the error goes away.

    BTW, I suspect that acSaveYes isn't doing what you think it is.This argument saves design changes that have been made to a form, it doesn't save data that has been entered.Linq ;0)>
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Tags for this Thread

Posting Permissions

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