Results 1 to 3 of 3
  1. #1
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211

    Instantiate a Class with Parameters?

    Hi,

    I think I know the answer to this, but just in case...

    Is it possible to instantiate a class in Access VBA with a parameter?

    In C# I can do that
    Code:
    MyClass ClassObject = New MyClass(myParameter)
    Can this be done with an Access class?
    I tried adding a parameter in the Class_Initialize event, but that caused a compile error.

    Alternatively, I could create an Init method which does take a parameter, then move the setup stuff out of Class_Initialize and put it into the Init method. Then would have to always call the Init method before any other methods.

    Thanks...

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    add the param after you instantiate the class.

    set cls = new cMyClass
    cls.runRoutine("param")

  3. #3
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks ranman. That's what I thought. Would have been nice if you could have an optional parameter in the class initialize method. Oh well....

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 04-29-2019, 03:16 AM
  2. Need Help With a Class
    By Alaskanhawg in forum Access
    Replies: 8
    Last Post: 12-14-2013, 05:46 PM
  3. Replies: 9
    Last Post: 01-08-2013, 12:40 PM
  4. Class Method
    By AndreT in forum Programming
    Replies: 3
    Last Post: 01-20-2011, 02:18 AM
  5. Class in Access
    By Huddle in forum Access
    Replies: 2
    Last Post: 07-15-2010, 04:08 PM

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
  •  
Other Forums: Microsoft Office Forums