P
Peter
Hello,
I have the following code:
Function CreateCrossRefCollection(sRange As Range) As Collection
Dim aField As Field, FieldName As String, ReqName As String
Dim tCase As String, TCaseObj As TCaseClass
Dim XRefCollection As Collection, ReqCollection As Collection
Set XRefCollection = New Collection
For Each aField In sRange.Fields
FieldName = UCase(aField.Code)
If aField.Type = wdFieldSequence Then
If InStr(FieldName, "TESTSECTIONLEVEL") Then
tCase = "VTKP_" & Format(aField.Result, "00") & "_"
ElseIf InStr(FieldName, "TESTMODULELEVEL") Then
tCase = tCase & Format(aField.Result, "00") & "_"
ElseIf InStr(FieldName, "TESTCASEID") Then
tCase = tCase & Format(aField.Result, "00")
End If
ElseIf aField.Type = wdFieldRef Then
If InStr(FieldName, "REF REQ_") Then
ReqName = Mid(FieldName, 5, 13)
Set TCaseObj = New TCaseClass
TCaseObj.Name = tCase
If CollectionItemExists(ReqName, XRefCollection) Then
Set ReqCollection = XRefCollection(ReqName)
ReqCollection.Add TCaseObj, tCase
Else
Set ReqCollection = New Collection
ReqCollection.Add TCaseObj, tCase
XRefCollection.Add ReqCollection, ReqName
End If
End If
End If
Next aField
Set CreateCrossRefCollection = XRefCollection
End Function
I have a document that contains a traceability matrix (Requirement numbers
with corresponding test cases). The test cases are numbered using three
SEQuence fields: "TestSectionLevel", "TestModuleLevel" and "TestID". The test
case contains crossreferences to the requirements in the trace matrix.
The code is intended to scan a predifined range in the document for the test
case fields and then locate the crossreference fields. I want one collection
for each requirement that contains one TCaseObj object (contains the test
case ID) per test case for that requirement.
Notice that this is a function. It returns a collection that contains one
collection object for each requirement found (key is reqName).
The line: "Set ReqCollection = XRefCollection(ReqName)" works perfectly when
the code is running but if I put a break in the very last line of this
function and then try to execute that line, I get the following error:
"Runtime Error '5' Invalid procedure call or argument".
I have looked at this code until I am blue in the face and cannot figure out
why I cannot retrieve the collection object using the key. Likewise, the
procedure that calls this function cannot retrieve objects from the
collection using the key.
Anybody got any ideas what is going on here?
Thanks,
Peter
I have the following code:
Function CreateCrossRefCollection(sRange As Range) As Collection
Dim aField As Field, FieldName As String, ReqName As String
Dim tCase As String, TCaseObj As TCaseClass
Dim XRefCollection As Collection, ReqCollection As Collection
Set XRefCollection = New Collection
For Each aField In sRange.Fields
FieldName = UCase(aField.Code)
If aField.Type = wdFieldSequence Then
If InStr(FieldName, "TESTSECTIONLEVEL") Then
tCase = "VTKP_" & Format(aField.Result, "00") & "_"
ElseIf InStr(FieldName, "TESTMODULELEVEL") Then
tCase = tCase & Format(aField.Result, "00") & "_"
ElseIf InStr(FieldName, "TESTCASEID") Then
tCase = tCase & Format(aField.Result, "00")
End If
ElseIf aField.Type = wdFieldRef Then
If InStr(FieldName, "REF REQ_") Then
ReqName = Mid(FieldName, 5, 13)
Set TCaseObj = New TCaseClass
TCaseObj.Name = tCase
If CollectionItemExists(ReqName, XRefCollection) Then
Set ReqCollection = XRefCollection(ReqName)
ReqCollection.Add TCaseObj, tCase
Else
Set ReqCollection = New Collection
ReqCollection.Add TCaseObj, tCase
XRefCollection.Add ReqCollection, ReqName
End If
End If
End If
Next aField
Set CreateCrossRefCollection = XRefCollection
End Function
I have a document that contains a traceability matrix (Requirement numbers
with corresponding test cases). The test cases are numbered using three
SEQuence fields: "TestSectionLevel", "TestModuleLevel" and "TestID". The test
case contains crossreferences to the requirements in the trace matrix.
The code is intended to scan a predifined range in the document for the test
case fields and then locate the crossreference fields. I want one collection
for each requirement that contains one TCaseObj object (contains the test
case ID) per test case for that requirement.
Notice that this is a function. It returns a collection that contains one
collection object for each requirement found (key is reqName).
The line: "Set ReqCollection = XRefCollection(ReqName)" works perfectly when
the code is running but if I put a break in the very last line of this
function and then try to execute that line, I get the following error:
"Runtime Error '5' Invalid procedure call or argument".
I have looked at this code until I am blue in the face and cannot figure out
why I cannot retrieve the collection object using the key. Likewise, the
procedure that calls this function cannot retrieve objects from the
collection using the key.
Anybody got any ideas what is going on here?
Thanks,
Peter