+ Reply to Thread
Results 1 to 13 of 13

workng with class modules, how to call a sub

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    workng with class modules, how to call a sub

    how do i call a class module sub from a userform?

    i have the following code but it fails:

    Please Login or Register  to view this content.
    i set the instance property of the class module to PublicNotCreatable and expected the code to run.

    What am i not doing right?
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: workng with class modules, how to call a sub

    so i now know what PublicNotCreatable is used for, and yes i need that setting for the class (so that it can be called from Personal.xlsb). the more i read, i realize that i need two new events, one for the scrollbar change and one for the label click event.

    can someone help me with that?

  3. #3
    Registered User
    Join Date
    07-26-2020
    Location
    Israel
    MS-Off Ver
    365
    Posts
    16

    Re: workng with class modules, how to call a sub

    So first you need to instantiate the class

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: workng with class modules, how to call a sub

    yup, was on the right track but it error's out on the oCalendar.SBChange, gives me a run time error 9 subscript out of range.

    what do i need to do?

  5. #5
    Registered User
    Join Date
    07-26-2020
    Location
    Israel
    MS-Off Ver
    365
    Posts
    16

    Re: workng with class modules, how to call a sub

    I am getting multiple compile error's when Debugging your file, making it very hard to focus on one issue

    please run "Compile VBAProject" from the Debug tab to find each compile error

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: workng with class modules, how to call a sub

    here i did that

    Attachment 688561

    and here is the file. note that i made cal a public, but still get error on cal.SBChange.

    thoughts?
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-26-2020
    Location
    Israel
    MS-Off Ver
    365
    Posts
    16

    Re: workng with class modules, how to call a sub

    Inside your clsCalendar Initialize you suddenly call the uf_clsCalendar.scrollBar that in turn calls back to the clsCalendar

    the problem is that the Class_Initialize has not finished (Reach End Sub) and cal has not been created yet.

    Please Login or Register  to view this content.

    Tip: use F8 to step into your code and run line by line till you get to error

  8. #8
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: workng with class modules, how to call a sub

    so i commented out "cal.SBChange" and left the code in ScrollBar1_Change just so that the calendar would show. so my question is how can i move that code into the class module?

    Please Login or Register  to view this content.
    i have an event (that i don't know how to code) but not really sure that i know what im doing.

    Please Login or Register  to view this content.
    , did i do that right?

    so if the event statement is correct, then i need to code for the event, correct?

    let me know what you think.

  9. #9
    Registered User
    Join Date
    07-26-2020
    Location
    Israel
    MS-Off Ver
    365
    Posts
    16

    Re: workng with class modules, how to call a sub

    Created this file, hopefully it will help you with your project.
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: workng with class modules, how to call a sub

    not sure what i am looking at, it looks like this is just a userform with no class module...

    so just so that you know, i have the userform calendar working fine (without using class modules) though your code is shorter than mine.

    the question that i have is how to use class modules with my calendar. i was able to get the userform init working with no problems but ran into issues with ScrollBar1_Change. how can that be done?

    im sure that i will need to create two events, one for the scrollbar change and one for the lable click. Is that something you can help me with?

  11. #11
    Registered User
    Join Date
    07-26-2020
    Location
    Israel
    MS-Off Ver
    365
    Posts
    16

    Red face Re: workng with class modules, how to call a sub

    So I guess my problem is that I don't understand why you need to call the userform from a class.

    I changed my file a little, (also fixed a bug I found). See if this is what you need.

    If not then I would be happy for you to explain the logic behind what you are trying to accomplish

    By the way... I am really enjoying building up my Calendar, so thanks for that at least
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: workng with class modules, how to call a sub

    ok, so some background

    for me class modules are the holy grail and mysterious parts of VBA. Have been waiting for a project to apply that and figured my calendar might be the right one to do it with. so the reason is just to work my way through class modules. now if (due to coding) that means this is not the right project, then just tell me. if not, i would like to get this working if possible.

    if you open up my file, you will see a class calendar button. all is working but i would like to move the code for SBChange from the userform to the class module. it seems to me that i need two events, one is for the ScrollBar1_Change and the other is Label_Click.

    is that something you can help me with?
    Attached Files Attached Files
    Last edited by dmcgov; 07-28-2020 at 07:34 AM.

  13. #13
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: workng with class modules, how to call a sub

    marking this solved as i am asking the question in a different way. robin, please visit this thread instead:

    New Post

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Class Modules in VBA - Can someone explain how I can use it.
    By MThrossell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-29-2014, 10:54 AM
  2. Class Modules Help
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-23-2009, 06:45 AM
  3. Class Modules?
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2008, 06:39 AM
  4. Understanding Class Modules
    By MartinShort in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2008, 03:52 AM
  5. Class Modules
    By MattShoreson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-22-2006, 06:40 AM
  6. [SOLVED] Basic question - modules and class modules - what's the difference?
    By Mark Stephens in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-08-2005, 07:08 AM
  7. [SOLVED] Class Modules
    By Pavlos in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-19-2005, 02:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1