We assume this relates to this post http://www.access-programmers.co.uk/ubb/Forum1/HTML/008348.html
there is a search button here which will a great many examples of using this code, but you should be aware that you cannot cancel the main form from a sub since the record is automatically saved as soon as you start entering data in the subform, you'll have to delete the main form record if you don't want to save it.