I may know why the rule is running when you are not ready for it to run. It looks like the word "serialNumber" is the name of a local parameter, because it is blue in your post. Any time you use a local parameter in a local iLogic rule, and its name is blue, that creates a sort of 'trigger' scenario. Then any time the value of that parameter changes, it will instantly trigger that rule to run. So when you are entering the value of the "serialNumber" parameter using the form, it will instantly run this rule, because of the way you are using the local parameter within it. To eliminate this unwanted behavior, you could specify the parameter in a different way, so its name doesn't turn blue.
So you would use it like this:
Parameter("serialNumber")
instead of like this:
serialNumber
That would stop the rule from automatically running when the value of that parameter changes, due to you entering its value from the form.
Also, just in case you weren't aware, using 'True' within the 'SaveAs' sub, causes it to act like 'SaveCopyAs', which saves off a copy of the new document, while the previously active document remains open and active. If you want the new copy document to be the active document after this line of code, you should use False in the 'SaveAs' sub. Then you wouldn't have to launch the the newly created copy document, and wouldn't have to specify it from the set of all documents, and wouldn't have to save it, because you already have saved it.
I've included a couple more ideas in this code for you to consider. There are many ways to do this. As good practice though, once I've established a document variable, I like to stick with it, rather than redefining the active document multiple times within the same code. Sometimes that means slightly more code, but that's alright because once the code is working and stable, you don't have to worry about it anymore. It just does its job in the background, as intended.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oExistingDoc As AssemblyDocument = ThisApplication.ActiveDocument
'the following is retrieving the value of a parameter named "serialNumber" and setting its value
'as the value of a new variable here within this rule
Dim oSN As String = Parameter("serialNumber")
'or
'Dim oSN As String = oExistingDoc.ComponentDefinition.Parameters.Item("serialNumber").Value
'or if "serialNumber" is an iProperty instead of a parameter
'Dim oSN As String = iProperties.Value("Custom","serialNumber")
Dim oNewName As String = IO.Path.GetDirectoryName(oExistingDoc.FullFileName) & "\" & oSN & ".iam"
oExistingDoc.SaveAs(oNewName, True)
Dim oNewDoc As AssemblyDocument = ThisApplication.Documents.Open(oNewName)
oNewDoc.Activate
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.
If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS
Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield

(Not an Autodesk Employee)