none
VBA Objects driving me crazy RRS feed

  • Question

  • In order to understand how VBA objects work, I built the old chestnut Shapes.

    The idea is that the base class is Shape, with two “dimension” fields, D1 and D2, and an empty function Area to provide the area of the object. The class Rect “derives” from Shape.  

     

    The ShapeRect project compiles and runs when I include a test Module.

    So I remove the test Module and save the Project.

    I open a new database and insert the test Module into CallerB. I define the object Project as a Reference.

    And now, Caller doesn’t recognize anything in ShapeRect.

    “Dim r as Rect” stops the compiler with “unrecognized type.”

    Is this “normal”, or is there a way to get this to work?

    My goal is to separate code into recognizably independent pieces using Classes and Projects, but I’m failing.

    Happy Thanksgiving!



    peter n roth - http://PNR1.com, Maybe some useful stuff

    Thursday, November 26, 2015 4:34 AM

Answers

  • Finally found this in the Help file under "Project":

    Set a reference to the project in another Microsoft Access database when you want to call a public procedure that's defined within a standard module in that database. You can't call procedures that are defined within a class module or procedures in a standard module that are preceded with the Private keyword.


    peter n roth - http://PNR1.com, Maybe some useful stuff

    • Marked as answer by Peter N Roth Friday, November 27, 2015 2:43 AM
    Friday, November 27, 2015 2:42 AM

All replies

  • You needto make your class visible to others:

    Thursday, November 26, 2015 10:34 PM
  • Thanks Stefan, but the NotCreatable part of PublicNotCreatable means that "New" is now illegal, so I can't make an object.

    peter n roth - http://PNR1.com, Maybe some useful stuff

    Friday, November 27, 2015 2:22 AM
  • Finally found this in the Help file under "Project":

    Set a reference to the project in another Microsoft Access database when you want to call a public procedure that's defined within a standard module in that database. You can't call procedures that are defined within a class module or procedures in a standard module that are preceded with the Private keyword.


    peter n roth - http://PNR1.com, Maybe some useful stuff

    • Marked as answer by Peter N Roth Friday, November 27, 2015 2:43 AM
    Friday, November 27, 2015 2:42 AM