the code snippet i posted would need to be placed inside a procedure (SUB)
possibly the click event for a command button, depending what you want, to start the code running