Consulting

Results 1 to 13 of 13

Thread: event procedures

  1. #1

    event procedures

    hi everyone

    i have some code wriiten for before update event and change event

    is it possible to call on these procedures either via another event or code?

    thanks

  2. #2
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    If you want to call the same code from multiple events, the best way is to put the code into a separate routine and call that routine from all required events. You can also call event procedures the same way you call other private procedures.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3

    event procedures

    thanks rory

    tried to call the change procedure using the following code

    application.run "'RingGaugeNew.xls'!Grade_Change"

    but this comes up with a an error saying the macro cant be found

    just checking it again to ensure i have typed it in correctly

    thanks

  4. #4
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    As I said, the best way is to put the code into a separate routine.
    What is 'Grade' and where are you trying to call the procedure from? Event procedures belong to objects, so if for example Grade is a combobox on a worksheet, you would need to use syntax like:
    [VBA]Application.Run "workbook.xls!sheet1.Grade_Change"[/VBA]
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5

    event procedures

    so for a form i would change sheet1 to the form name

    thanks

  6. #6
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    northernstar

    Why would you want to call these event procedures?

  7. #7
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You can't call a procedure in a form unless it is loaded, AFAIK.
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    rory

    I don't think that's actually the case, but I wonder why you would want to call them in the first place.

    Create a userform, add a button and give this a shot in a standard module.
    [vba]
    UserForm1.CommandButton1.Value = True
    [/vba]
    Or you could even remove Private from the event sub header and use this.
    [vba]
    Call UserForm1.CommandButton_Click
    [/vba]
    The command button will still work but I don't know if there are any implications. eg scope, visbility etc

  9. #9
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Yes, you can do that, but you are implicitly loading the userform the minute you refer to it. Using Application.Run won't work because you don't load the userform that way.
    Regards,
    Rory

    Microsoft MVP - Excel

  10. #10
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    rory

    Never realised that.

    Just knew you could call the events like that.

    I'd still like to know why the OP wants to do it anyway.

  11. #11
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    I can imagine why you might want the same code called; I can't see why you wouldn't just put the relevant code into its own routine, where it belongs...
    Regards,
    Rory

    Microsoft MVP - Excel

  12. #12
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    rory

    Perhaps the OP could utilize a class module?

    Hard to tell without more information. eg what the code does, what controls etc

    I can't recall which, if any controls, would have those events exposed in a class module.

  13. #13
    here is the file which i am working on

    seem to have got round the problem

    but also seem to have a lot of repeating codes

    i know my programming skills are not very good, but i am self taught and dont always follow good practise but get the result i need

    the form and programming is not finished yet

    i would appreciate your comments and advice, thanks
    any questions please let me know

Posting Permissions

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