Jerry is correct, by switching to end you exit the application. Using Exit sub and function would fix the problem