none
object doesn't contain the automation object Form RRS feed

  • Question

  • Hi

    Using a FE / BE database made by Access 2007 32bit. Now running Access 2013 32bit and - trying to - add a instruction to a macro. The macro starts by clicking av push-button.

    The macro runs as it should in both 2007 and 2013 in its original.

    I now tried to add a MessageBox to the macro as a new line in the end. But when I do I have the message "object doesn't contain the automation object Form"

    Next thing that happens is another message from Access - "Step thru macro" (from Swedish):

    Instruction:
    Set Value

    [Forms]![Bryggrader]![SubForm].[Forms]![Behandling]; 2

    Error no: 2950

    "Fun" thing is that:

    Set Value

    [Forms]![Bryggrader]![SubForm].[Forms]![Behandling]; 2 WORKS!

    If I remove the new MessageBox instruction the macro still causes the same error messages as above.
    "Fun" thing is that:

    Set Value

    [Forms]![Bryggrader]![SubForm].[Forms]![Behandling]; 2 WORKS!

    I now delete the push-button that starts the macro and copy an old one from a back up database. And now it works as i should.

    Why cant I add a simple line to an old macro?


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Thursday, September 17, 2015 4:09 PM

Answers

  • The following syntax is wrong:

    [Forms]![Bryggrader]![SubForm].[Forms]![Behandling]

    It should be:

    [Forms]![Bryggrader]![SubForm].[Form]![Behandling]

    A word of advice... You should consider renaming your sub-form from SubForm to something else like sfmMeaningfulName, or just sfm1.

    Additionally, you should attempt to create your procedures in VBA rather than macros.  VBA is much easier to debug and a more professional means of accomplishing tasks.  Furthermore, you have greater error handling ability in VBA.

    Hope this helps out...


    • Edited by RunningManHD Thursday, September 17, 2015 4:18 PM
    • Marked as answer by ForssPeterNova Thursday, September 17, 2015 5:28 PM
    Thursday, September 17, 2015 4:15 PM

All replies

  • Hi. Not really an answer but have you tried creating a brand new macro that does the same things as the old macro plus the MessageBox? Just to test, you know...
    Thursday, September 17, 2015 4:13 PM
  • The following syntax is wrong:

    [Forms]![Bryggrader]![SubForm].[Forms]![Behandling]

    It should be:

    [Forms]![Bryggrader]![SubForm].[Form]![Behandling]

    A word of advice... You should consider renaming your sub-form from SubForm to something else like sfmMeaningfulName, or just sfm1.

    Additionally, you should attempt to create your procedures in VBA rather than macros.  VBA is much easier to debug and a more professional means of accomplishing tasks.  Furthermore, you have greater error handling ability in VBA.

    Hope this helps out...


    • Edited by RunningManHD Thursday, September 17, 2015 4:18 PM
    • Marked as answer by ForssPeterNova Thursday, September 17, 2015 5:28 PM
    Thursday, September 17, 2015 4:15 PM
  • RunningManHD

    Thanks.

    The running Macro that works has this syntax: (swedish)
    [Formulär]![Bryggraderlagertank]![BryggraderRaderunderformulär].[Formulär]![Behandling]

    the name of my sub-form is not SubForm in the macro. It has a longer and meaningful name in Swedish :-)

    VBA or macros... I start with macros mostly. And keeps them when they contains few lines and works. In this case:

    1 Open form B normal
    2 Set Value
    3 Close form A

    This is an embedded Macro. Now when I try to save it, its not possible. The Macor Save as is greyed out.


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Thursday, September 17, 2015 4:53 PM
  • Hi DB guy

    I made a new macro, without the MessageBox. Just using the three lines:

    Open a Form B

    SetValue

    Close Form A

    I used, of course, Access 2013 Macro Editor. And the macro gives exactly the same errors as the original (when I on the original add a MessageBox and in the new one dont use a MessageBox.

    Confusing. Something to do with the Swedish versions of Access?


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Thursday, September 17, 2015 5:00 PM
  • Okay. One more check. Create a new blank database using 2013 and then create a macro there. If you don't get the error, then I would suspect something amiss in the old file. Just a thought...
    Thursday, September 17, 2015 5:16 PM
  • Hi

    I converted the macro to VBA

    Function BryggraderOpen()
    On Error GoTo BryggraderOpen_Err
    
        DoCmd.OpenForm "Bryggrader rader rader Vad som finns i vald lagertank", acNormal, "", "", , acNormal
        Forms![Bryggrader rader rader Vad som finns i vald lagertank]![Bryggrader Rader Rader Omtapp Filter etc underformulär].Form!Behandling = 2
        DoCmd.Close acForm, "Sammanställning av bryggder i lagertankar"
    
    
    BryggraderOpen_Exit:
        Exit Function
    
    BryggraderOpen_Err:
        MsgBox Error$
        Resume BryggraderOpen_Exit
    
    End Function

    And at first the code ended 

    ].Forms!Behandling = 2

    But it should be as RunningManHD said:

    ].Form!Behandling = 2

    Now the VBA code runs as an Event procerdure and I can add a MessageBox


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Thursday, September 17, 2015 5:28 PM
  • Hi Peter. Congratulations! Glad to hear you got it sorted out. Cheers!
    Thursday, September 17, 2015 5:36 PM
  • VBA or macros... I start with macros mostly. And keeps them when they contains few lines and works. In this case:

    Hi Peter,

    With VBA and proper parameters in the routines you can generalize the code to a very far extent.

    Going that direction you can re-use your code, and thus make very flexible though robust applications.

    Imb.

    Thursday, September 17, 2015 7:49 PM