Private Function DeleteTestAttachment(theTest As TDAPIOLELib.Test, _ AttachmentName As String) As Boolean ' Delete a test attachment ' This routine deletes the attachment of the test ' that best matches the AttachmentName. ' Attachment name may contain the wildcard "*" ' To see how to get a test object with the name ' and path, see the Test example: ' "Get a test object with name and path" Dim TestAttachFact As AttachmentFactory Dim attachList As List, TAttach As Attachment Dim theAttachment As Attachment Dim AttachFilter As TDFilter Dim FileName As String On Error GoTo FUNC_ERR DeleteTestAttachment = SUCCESS '--------------------------------------------- ' Use Test.Attachments to get the AttachmentFactory. Set TestAttachFact = theTest.Attachments '------------------------- ' Get the filter to find AttachmentName. Set AttachFilter = TestAttachFact.Filter ' Because the server files are concatenations ' of: ' "Test_#_" ' and ' the file name as seen in the UI ' the name must start with "*" AttachmentName = Trim(AttachmentName) Dim pos% pos = InStr(1, AttachmentName, "*") If pos = 1 Then AttachFilter.Filter("CR_REFERENCE") = _ AttachmentName Else AttachFilter.Filter("CR_REFERENCE") = _ "*" & AttachmentName End If '------------------------- ' Find the attachment Set attachList = _ TestAttachFact.NewList(AttachFilter.Text) ' There may be more that one match for *AttachmentName. ' For example, Test_99_AttachmentName and ' Test_99_SomeMoreChars_AttachmentName. ' For this example, we take the shortest name ' as the best match. Dim minLength As Integer minLength = 32000 For Each TAttach In attachList With TAttach If Len(.name) < minLength Then minLength = Len(.name) Set theAttachment = TAttach End If End With Next '------------------------- ' If the item is found, use the AttachmentFactory ' to delete it. If theAttachment Is Nothing Then errmsg = "Attachment " & AttachmentName & " not found" ErrHandler Null, "DeleteTestAttachment", errmsg, NON_FATAL_ERROR Else ' Dim msg$, rc ' msg = "Do you want to delete" _ ' & vbCrLf & theAttachment.name _ ' & vbCrLf & " from test " _ ' & vbCrLf & theTest.name _ ' & "(ID " & theTest.ID & ")?" ' rc = MsgBox(msg, vbYesNo) ' If rc = vbYes Then '----------------------------------------------------- Dim vControl As VCS Dim CheckOutOK As Boolean Set vControl = CheckoutTest(theTest, "Check out for attachments", CheckOutOK) If Not CheckOutOK Then GoTo FUNC_ERR ' Use AttachmentFactory.RemoveItem to delete the item. TestAttachFact.RemoveItem (theAttachment.ID) If Not CheckinTest(vControl, "Finished attaching files") Then GoTo FUNC_ERR ' End If End If Exit Function FUNC_ERR: DeleteTestAttachment = FAILURE End Function