If you literally want to change a code on document open, then you need an
AutoOpen macro that increments a document variable or document property and
updates fields. Within the document, use a field to show the property or
variable.
If you don't want to use a macro, then you might be able to make use of the
RevNum field, which counts the number of times the document has been saved.
However, if what you are really trying to do is use the document as a
template to produce numbered copies, you may find what you want here: