It sounds like the field/control on the main form (parent) that links the main form to the sub form doesn't have the required value, thus no subform records can be created. That would cause the error you describe. Often the approach is to open a main form with the parent field filled in and have that "cascade" to the subform. If the design doesn't allow for that, there are ways to prevent or handle your issue. One prevention is to have the subform invisible until that field is completed, although a label might be required to point that out. Another is to know the sequence of events for forms and controls, and (in your case) validate that the necessary controls contain data, and if not, terminate the process before the event occurs that causes the error.
On the handling side, virtually all code procedures should have an error handling routine, or at least, there should be one not too far up in the hierarchy. When a run time error (not a compile error) occurs, Access looks first in the module containing the code for an error handler. If not found, it looks backwards through any chain of procedure executions - kind of like going up river. If none is found, the default handler takes over. That is what you're experiencing.
If you want to post the code, I/we will see what we can come up with for an error handling routine - unless you want to Google it yourself.