If your in the form designer, and have the button on the screen, and double click the form, it should automatically open the code window for the command button "Click". You can NOT have any such "function", or "procedure" defined within that code... Thats what its probably complaining about... Do you have something like...
prepare some variables
more prep
..
..
do Something
return
function Something
now, whatever you were trying to call
anything else
endfunction
You can't do this inside a code window, you would have to rework how/where the possible "do something" function scenario... if your command button is a custom class, you could create your own new method on that, or have a seperate procedure file with stand-alone type functions.
>Hello Fabio,
>
>Thanks very much for your reply.
>
>But no headway yet. I would like to put code into a commandbutton on a form to instantiate a class. But the commandbutton does not accept the code with the error message "Methods and events cannot contain procedures or class definitions"
>
>Any help will be greatly appreciatiated.
>
>Thanks and regards,
>
>Steve.