PDA

View Full Version : event procedures



northernstar
11-08-2007, 03:39 AM
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

rory
11-08-2007, 03:50 AM
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.

northernstar
11-08-2007, 04:20 AM
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

rory
11-08-2007, 05:02 AM
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:
Application.Run "workbook.xls!sheet1.Grade_Change"

northernstar
11-08-2007, 06:05 AM
so for a form i would change sheet1 to the form name

thanks

Norie
11-08-2007, 06:31 AM
northernstar

Why would you want to call these event procedures?

rory
11-08-2007, 08:45 AM
You can't call a procedure in a form unless it is loaded, AFAIK.

Norie
11-08-2007, 09:26 AM
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.

UserForm1.CommandButton1.Value = True

Or you could even remove Private from the event sub header and use this.

Call UserForm1.CommandButton_Click

The command button will still work but I don't know if there are any implications. eg scope, visbility etc

rory
11-08-2007, 09:35 AM
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.

Norie
11-08-2007, 09:43 AM
rory

Never realised that.:oops:

Just knew you could call the events like that.

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

rory
11-08-2007, 09:47 AM
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...

Norie
11-08-2007, 09:57 AM
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.

northernstar
11-08-2007, 02:56 PM
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