Visual Basic Customization

Reply
Active Contributor
dlabreche
Posts: 26
Registered: ‎10-03-2007
Message 1 of 6 (98 Views)

writing to an Access 2003 database

98 Views, 5 Replies
06-02-2009 05:40 AM
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.
*Laurie
Message 2 of 6 (98 Views)

Re: writing to an Access 2003 database

06-02-2009 05:50 AM 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.
Active Contributor
dlabreche
Posts: 26
Registered: ‎10-03-2007
Message 3 of 6 (98 Views)

Re: writing to an Access 2003 database

06-02-2009 06:00 AM 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}
*Laurie
Message 4 of 6 (98 Views)

Re: writing to an Access 2003 database

06-02-2009 04:41 PM 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}
>
Active Contributor
dlabreche
Posts: 26
Registered: ‎10-03-2007
Message 5 of 6 (98 Views)

Re: writing to an Access 2003 database

06-03-2009 04:57 AM 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.
Active Contributor
dlabreche
Posts: 26
Registered: ‎10-03-2007
Message 6 of 6 (98 Views)

Re: writing to an Access 2003 database

06-03-2009 01:54 PM 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community