You can actually use DriveWorksXpress (a free design automation add-in inside SOLIDWORKS). With DWX, you can set up a master part and place it in known location. And when you need a different length part, just pull the DWX project to create the file with required number for you. In case the file already exists, it won't create a new file.
If that doesn't help then other option would be to get an add-in made which would automatically create the part number based on your requirements and would also check and compare with existing numbers.