- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I have created an assembly of iParts that users can modify by selecting values from a VBA user form. Once values are selected a copy of assembly is saved and each iPart is replaced to a different iPart and the required member row is selected.
The process works on my computer, but all other users in our company experience intermittent errors with it. I created a basic error log to show me around which lines of VBA code the process fails. It seems like the issue might be around not accessing the files and user parameters within the assembly like they haven't been set or found.
I was thinking it could be due to the fact that the new assembly is opened invisibly and it has the same VBA project name as the original, but I couldn't understand why it works without any issues on my computer. I have tried to replicate the errors other users experienced (i.e., opening multiple different documents in Inventor that also have VBA projects with some code in it), but with no luck.
I am using Inventor Professional 2019 and have created the code within VBA editor. All the iParts required by the assembly are checked into Vault. The code is activated by an iLogic rule that calls a macro within the document. The macro runs through a module, that shows a VBA form. I created a function to ensure I am accessing the required VBA project within my current assembly, please see below:
Public Function AssyDocDef() As AssemblyDocument
Const sProcName As String = "AssyDocDef"
On Error GoTo ErrorHandler
' This should ensure that the code works even if there are multiple documents open
' and of different types
Dim oDoc As Document
Dim oDocDisplayName As String
Dim oVBAProjectName As String
On Error Resume Next
For Each oDoc In ThisApplication.Documents
' should make sure this VBA project is actually within template document, not any other newly created assembly
oVBAProjectName = oDoc.VBAProject.Name
oDocDisplayName = oDoc.DisplayName
If (oVBAProjectName = "ThisConfigVBAProject") And (oDocDisplayName = "This-Assembly-Template") Then
Set AssyDocDef = oDoc
Else
' This is not the template assembly document
End If
Next
Dim oMsgBoxCritical As VbMsgBoxStyle
oMsgBoxCritical = vbOKOnly & vbCritical
If AssyDocDef Is Nothing Then
Call Error_Handle(sProcName, "Custom", "The template assembly definition was not set.", _
Err.Source, Erl)
Call MsgBox("Inventor failed to set an assembly definition of the template assembly configurator." & _
vbCrLf & "Please close the configurator, re-open and re-start it.", _
oMsgBoxCritical, "Critical Error - Template Assembly Configurator")
Exit Function
Else
End If
Exit Function
ErrorHandler:
Call Error_Handle(sProcName, Err.Number, Err.Description, Err.Source, Erl)
End Function
After assembly definition has been set, I am accessing user parameters and information selected within the form by the user to obtain new assembly name and names of parts to be replaced.
Could anyone please point me in the right direction how to ensure this works for all our users?
Thanks in advance!
Solved! Go to Solution.