VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

writing to an Access 2003 database

5 REPLIES 5
Reply
Message 1 of 6
dlabreche
457 Views, 5 Replies

writing to an Access 2003 database

I need help with writing to a table in a Microsoft Access 2003 database. I am using AutoCAD VBA in AutoCAD 2009. I have been referring to AutoCAD VBA 2004 (Sutphin, 2004). The commands listed in the book are not working for me. I have written several VBA programs for use in AutoCad but this is my first time trying to write to a database and I am totally lost.
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: dlabreche

Hi dlabreche,

Post your code in a text file so we can read it in a newsreader.

Autodesk are still mucking about pretending they are going to fix this
stupid system and people using Newsreader will not be able to read your
code if you post from the web site.

Regards,


Laurie Comerford


dlabreche@gateprecast.com wrote:
> I need help with writing to a table in a Microsoft Access 2003 database.
> I am using AutoCAD VBA in AutoCAD 2009. I have been referring to AutoCAD
> VBA 2004 (Sutphin, 2004). The commands listed in the book are not
> working for me. I have written several VBA programs for use in AutoCad
> but this is my first time trying to write to a database and I am totally
> lost.
Message 3 of 6
dlabreche
in reply to: dlabreche

here is the code...I have also attached it as a text file

{
Sub d_takeoff()

Dim ssetObj As AcadSelectionSet
Dim blockObj As AcadBlock
Dim i As Integer
Dim attributeObj As AcadAttribute
Dim blockRefObj As AcadBlockReference
Dim strAttributes As String
Dim varAttributes As Variant
Dim ent As Variant
Dim temp As String
Dim objSelection As AcadSelectionSet
Dim objSS As AcadSelectionSet
Dim strSSList As String
Dim name As String
Dim objWork As Object
Dim objAttribs As Collection
Dim objent As AcadEntity
Dim objBref As AcadBlockReference
Dim varAttribs As Variant
Dim strAttribs As String
Dim intI As Integer
Dim count As Integer
Dim listOfAttributes(20) As String
Dim panelMark As String
'Dim oAccess As New AD0DB.Connection
Dim PanelCount As Integer
Dim timeToStop As Boolean


timeToStop = "False"
Do
With ThisDrawing.Utility
Set ssetObj = ThisDrawing.SelectionSets.Add("1")
ssetObj.SelectOnScreen
count = 1
For Each ent In ssetObj
Set objent = ent
Set objBref = objent
varAttribs = objBref.GetAttributes
strAttribs = "Blockname: " & objBref.name & vbCrLf
For intI = LBound(varAttribs) To UBound(varAttribs)
strAttribs = strAttribs & " Tag(" & intI & "): " & _
varAttribs(intI).TagString & vbTab & " value(" & intI & "): " & _
varAttribs(intI).TextString & vbCrLf
If varAttribs(intI).TagString = "MARK" Then
listOfAttributes(0) = varAttribs(intI).TagString
End If
If varAttribs(intI).TagString = "D" Then
listOfAttributes(count) = varAttribs(intI).TextString
count = count + 1
End If
Next
MsgBox strAttribs
Next

ssetObj.Clear
ssetObj.Delete
End With
Loop Until timeToStop

oAccess.Open "Provider=Microsoft.Jet.OLEDB.4.0; & "Data Source=" & "C:\AutoCAD-VBA.mbd" & ";"
oRecordset.Open "Select * from layers", oAccess, adOpenKeyset, adLockOptimistic


End Sub}
Message 4 of 6
Anonymous
in reply to: dlabreche

Hi dlabreche,


The attached Word document has some code and comments which may prove
helpful.

Regards,


Laurie Comerford


dlabreche@gateprecast.com wrote:
> here is the code...I have also attached it as a text file { Sub
> d_takeoff() Dim ssetObj As AcadSelectionSet Dim blockObj As AcadBlock
> Dim i As Integer Dim attributeObj As AcadAttribute Dim blockRefObj As
> AcadBlockReference Dim strAttributes As String Dim varAttributes As
> Variant Dim ent As Variant Dim temp As String Dim objSelection As
> AcadSelectionSet Dim objSS As AcadSelectionSet Dim strSSList As String
> Dim name As String Dim objWork As Object Dim objAttribs As Collection
> Dim objent As AcadEntity Dim objBref As AcadBlockReference Dim
> varAttribs As Variant Dim strAttribs As String Dim intI As Integer Dim
> count As Integer Dim listOfAttributes(20) As String Dim panelMark As
> String 'Dim oAccess As New AD0DB.Connection Dim PanelCount As Integer
> Dim timeToStop As Boolean timeToStop = "False" Do With
> ThisDrawing.Utility Set ssetObj = ThisDrawing.SelectionSets.Add("1")
> ssetObj.SelectOnScreen count = 1 For Each ent In ssetObj Set objent =
> ent Set objBref = objent varAttribs = objBref.GetAttributes strAttribs =
> "Blockname: " & objBref.name & vbCrLf For intI = LBound(varAttribs) To
> UBound(varAttribs) strAttribs = strAttribs & " Tag(" & intI & "): " & _
> varAttribs(intI).TagString & vbTab & " value(" & intI & "): " & _
> varAttribs(intI).TextString & vbCrLf If varAttribs(intI).TagString =
> "MARK" Then listOfAttributes(0) = varAttribs(intI).TagString End If If
> varAttribs(intI).TagString = "D" Then listOfAttributes(count) =
> varAttribs(intI).TextString count = count + 1 End If Next MsgBox
> strAttribs Next ssetObj.Clear ssetObj.Delete End With Loop Until
> timeToStop oAccess.Open "Provider=Microsoft.Jet.OLEDB.4.0; & "Data
> Source=" & "C:\AutoCAD-VBA.mbd" & ";" oRecordset.Open "Select * from
> layers", oAccess, adOpenKeyset, adLockOptimistic End Sub}
>
Message 5 of 6
dlabreche
in reply to: dlabreche

Thanks for all the work you did.

Today, I will work through your comments and let you know how I do.

Thanks.
Message 6 of 6
dlabreche
in reply to: dlabreche

Thanks for your help. Between what you showed me and a little more studying on my own, I was able to write to Access.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost