Results 1 to 6 of 6

Thread: Calling a procedure with a Userform

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    Upstate NY
    Posts
    19

    Calling a procedure with a Userform

    I hope I explain this well.

    I have 2 workbooks. One is a compilation ofdata from 4 different worksites. The other holds the monthly totals from the first book on a sheet that shows Jan thru Dec in each year, with the last several years for comparison.
    2000 2001 2002 2003 2004
    Jan
    Feb
    March (just to give you an idea)

    i have the macro worked out to open the second book, and copy/paste the info to the proper site, month year (a macro for each month). What I don't have is a way to Call the proper month. I created a user form with OptionButtons, one for each month. Now it was easy enough to plug in
    OptionButton1_Click()
    Sub
    Call January
    End Sub

    But it executes immediately, as soon as I click the Month (optionButton). I wanted a way to protect myself from clicking too quickly and making a mistake, so I wanted to be able to click the month, and then press ENTER to execute the Call. This way I could look things over before I make a mistake.

    Should I use check boxes instead? Any suggestions would be appreciated.
    If I have been unclear, please let me know and I will try to clarify.

    Thanks again for your help.

    Don

    Edit: I use Office XP 2002. Also, I tried declaring a variable (eg myMonth),
    and then
    Call myMonth
    but it simply will not do it. ( i obviously could have written it wrong) I keep getting the error "Expexted Sub, Function, or procedure"

    Thanks
    Last edited by Toolman; Feb 11th, 2005 at 05:10 PM.
    Don

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Calling a procedure with a Userform

    You should use a checkbox to replace the option button and a command button
    to execute after you are sure that it is the option you really want.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    Upstate NY
    Posts
    19

    Re: Calling a procedure with a Userform

    Thanks, RobDog;

    If possible, could you give a short example of the code. I'm confused as to how to implement this. Thanks,

    Don
    Don

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Calling a procedure with a Userform

    Place the code in the option button in a command button. Then add a checkbox. When you click
    the command button you check the value of the checkbox and act accordingly.

    VB Code:
    1. Private Sub CommandButton1_Click()
    2.     If CheckBox1.Value = True Then
    3.         'do code that was in your optionbutton
    4.        
    5.     End If
    6. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    Upstate NY
    Posts
    19

    Resolved Re: Calling a procedure with a Userform(Resolved)

    Thank you so much for your help. It may seem silly but I had such a hard time working that out.

    Thanks again.

    Don
    Don

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Calling a procedure with a Userform

    Dont worry about it. We all have those kind of days
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width