I have been looking for a way to expand it to update the block attributes after modifying the TableDef but with no success.
What I am trying to do is, after populating the Attribute Table, run an update query, then send the updated TableDef back to the attributes. I am not sure how to pull it back and then loop it through in order to update the attribute blocks
I really appreciate any help that can be provided. I have been searching and working at this for days.
Expand|Select|Wrap|Line Numbers
- Sub Export_Access_Attributes() 'Written by Neopa
- ' Open database and delete old records if exist
- ' ---------------------------------------------
- Dim dbs As DAO.Database
- Dim dbsName As String
- Dim activeDoc As AcadDocument
- Dim DocLength As Integer
- Dim Shortlength As Integer
- Dim DwgPath As String
- Dim DwgName As String
- Dim DocName As String
- Dim data As DAO.Recordset
- Dim TableDef As String
- Dim Attribs As Variant 'Defaults to Variant
- Dim Handle As String
- Dim blockName As String
- Dim tag As String
- Dim Loops As String
- Dim Address As String
- Dim Label1 As String
- Dim Label2 As String
- Dim Device_Label As String
- Dim Extended_Label As String
- Dim Qty As String
- Dim Model_Num As String
- Dim Description As String
- Dim Vendor As String
- Dim CSFM_Num As String
- Dim ssnew As Object
- Dim setObj As Object
- Dim setColl As AcadSelectionSets
- Dim Entity As AcadEntity
- Dim blkEntity As AcadBlockReference
- Dim i As Variant 'Defaults to Variant
- ' Strip off extension .dwg
- ' -------------------------------
- Set activeDoc = ThisDrawing.Application.ActiveDocument
- DocName = activeDoc.Name
- DocLength = Len(DocName)
- Shortlength = DocLength - 4
- DwgPath = activeDoc.Path
- DwgName = Left(DocName, Shortlength)
- dbsName = "Project_Drawings.mdb"
- Set dbs = DBEngine.OpenDatabase(DwgPath & "\" & dbsName) 'Path to be C:\Blocks Folder
- ' Open recordset in table
- ' -----------------------
- ' Determine Tables Def
- ' --------------------------
- TableDef = "Attribute Report1"
- Set data = dbs.OpenRecordset(TableDef, dbOpenDynaset)
- ' Clear old values from table
- ' ---------------------------
- dbs.Execute "DELETE * FROM [Attribute Report1]", dbFailOnError
- ' Make Selection set of Blocks
- ' ----------------------------
- ThisDrawing.ActiveSpace = acModelSpace
- With activeDoc
- Set setColl = .SelectionSets
- For Each setObj In .SelectionSets
- If setObj.Name = "VBA" Then
- .SelectionSets.Item("VBA").Delete
- Exit For
- End If
- Next
- Set ssnew = activeDoc.SelectionSets.Add("VBA")
- End With
- ssnew.Select acSelectionSetAll
- ' Get Attribute values
- ' ---------------------
- For Each Entity In ssnew
- If Entity.ObjectName = "AcDbBlockReference" Then
- Set blkEntity = Entity
- If blkEntity.HasAttributes Then
- Attribs = blkEntity.GetAttributes
- For i = LBound(Attribs) To UBound(Attribs)
- Select Case Attribs(i).TagString
- Case "HANDLE"
- Handle = Attribs(i).TextString
- Case "BLOCKNAME"
- blockName = Attribs(i).TextString
- Case "TAG"
- tag = Attribs(i).TextString
- Case "LOOP"
- Loops = Attribs(i).TextString
- Case "ADDRESS"
- Address = Attribs(i).TextString
- Case "LABEL1"
- Label1 = Attribs(i).TextString
- Case "LABEL2"
- Label2 = Attribs(i).TextString
- Case "DEVICE_LABEL"
- Device_Label = Attribs(i).TextString
- Case "EXTENDED_LABEL"
- Extended_Label = Attribs(i).TextString
- Case "QTY"
- Qty = Attribs(i).TextString
- Case "MODEL_NUM"
- Model_Num = Attribs(i).TextString
- Case "DESCRIPTION"
- Description = Attribs(i).TextString
- Case "VENDOR"
- Vendor = Attribs(i).TextString
- Case "CSFM_NUM"
- CSFM_Num = Attribs(i).TextString
- End Select
- Next i
- ' Fill Database Table-----------------
- If Handle = "" Then Handle = " "
- If blockName = "" Then blockName = " "
- If tag = "" Then tag = " "
- If Loops = "" Then Loops = " "
- If Address = "" Then Address = " "
- If Label1 = "" Then Label1 = " "
- If Label2 = "" Then Label2 = " "
- If Device_Label = "" Then Device_Label = " "
- If Extended_Label = "" Then Extended_Label = " "
- If Qty = "" Then Qty = " "
- If Model_Num = "" Then Model_Num = " "
- If Description = "" Then Description = " "
- If Vendor = "" Then Vendor = " "
- If CSFM_Num = "" Then CSFM_Num = " "
- data.AddNew
- data!Handle = "'" & Entity.Handle
- data!blockName = blockName
- data!tag = tag
- data!Address = Address
- data!Label1 = Label1
- data!Label2 = Label2
- data!Device_Label = Device_Label
- data!Extended_Label = Extended_Label
- data!Qty = Qty
- data!Model_Num = Model_Num
- data!Description = Description
- data!Vendor = Vendor
- data!CSFM_Num = CSFM_Num
- data.Update
- End If
- End If
- Next Entity
- '************************************************************
- ' 'HERE is where the code to pull updated table from access goes…
- '' Attribs(0).TextString = "THIS IS THE NEW NEW VALUE!"
- '
- ' ' Get the attributes again
- ' Dim newAttribs As Variant
- ' newAttribs = blkEntity.GetAttributes
- '
- ' ' Again, display the tags and values
- ' strAttributes = ""
- ' For i = LBound(Attribs) To UBound(Attribs)
- ' strAttributes = strAttributes + " Tag: " + _
- ' newAttribs(i).TagString + vbCrLf + _
- ' " Value: " + newAttribs(i).TextString
- '************************************************************
- ' Close Database
- ' --------------
- data.Close
- dbs.Close
- Set data = Nothing
- Set dbs = Nothing
- ssnew.Delete
- End Sub