Writing Autocad data to AccessXP

Writing Autocad data to AccessXP

Anonymous
Not applicable
410 Views
7 Replies
Message 1 of 8

Writing Autocad data to AccessXP

Anonymous
Not applicable
Hello,
I'm working on putting line info into an Access database. I want to be able
to create a new table each time i run the program. If I create the table
named with/by a string input by the user the table is created in Access,
but if I continue on and try to input information (after having created the
table by code) it doesn't get written. If i take out the part where i
create the table and use a table I made manually then the info gets written
to the table. How would I create the table and then write to it. I suspect
the problem is in the 'openrecordset' line, but am not sure. Also, how
would i write the code to specify how many decimal places to show when the
info gets to the table? FYI: the variables i'm assigning to the fields are
public variables from the code that extracts the line info.

Thank you,

r
0 Likes
411 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
Show some code, particularly that which creates the table and writes the
record.
--
John Goodfellow
irtfnm
use john at goodfellowassoc dot com


"RHeldt" wrote in message
news:5DE6535BA72EE2A50499BF5A3604F1A5@in.WebX.maYIadrTaRb...
> Hello,
> I'm working on putting line info into an Access database. I want to be
able
> to create a new table each time i run the program. If I create the table
> named with/by a string input by the user the table is created in Access,
> but if I continue on and try to input information (after having created
the
> table by code) it doesn't get written. If i take out the part where i
> create the table and use a table I made manually then the info gets
written
> to the table. How would I create the table and then write to it. I
suspect
> the problem is in the 'openrecordset' line, but am not sure. Also, how
> would i write the code to specify how many decimal places to show when the
> info gets to the table? FYI: the variables i'm assigning to the fields
are
> public variables from the code that extracts the line info.
>
> Thank you,
>
> r
>
>
0 Likes
Message 3 of 8

Anonymous
Not applicable
The table "tettt" was created with the code that is remmed out. Now the
unremmed part won't write either. It exits after the "openrecordset"
method.

Public Sub coordadd()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Tdf As TableDef
Dim prploop As Property
Dim strName As String

'''''Set db = OpenDatabase("C:\Aplace\Databases\yeah.mdb")
'''''MsgBox "Enter a name for the table."
'''''Me.Show
'''''strName = txtPath.Text
'''''Set Tdf = db.CreateTableDef(strName)
'''''
'''''With Tdf
''''' .Fields.Append .CreateField("Section", dbText)
''''' .Fields.Append .CreateField("startX", dbText)
''''' .Fields.Append .CreateField("startY", dbText)
''''' .Fields.Append .CreateField("endX", dbText)
''''' .Fields.Append .CreateField("endY", dbText)
''''' '''Debug.Print "Properties of new tabledef object " & _
''''' '''"before appending to collection."
'''''''' For Each prploop In .Properties
'''''''' On Error Resume Next
'''''''' If prploop <> "" Then Debug.Print " " & _
'''''''' prploop.Name & " = " & prploop
'''''''' On Error Resume Next
'''''''' Next prploop
''''' db.TableDefs.Append Tdf
''''' db.TableDefs.Refresh
''''' db.Close
'''''
'''''End With
Set db = OpenDatabase("C:\Aplace\Databases\yeah.mdb")
Set rs = db.OpenRecordset("SELECT * FROM tett")
'Debug.Print rs.Name
'db.CreateTableDef
'rs.MoveFirst
rs.AddNew
rs.Fields("Section").Value = Strsec
rs.Fields("startX").Value = Dblstx
rs.Fields("startY").Value = Dblsty
rs.Fields("endX").Value = Dblepx
rs.Fields("endY").Value = Dblepy
rs.Update
rs.Close
db.Close
End Sub
0 Likes
Message 4 of 8

Anonymous
Not applicable
Try this:



Instead of rs.Fields("xxxxxx").Value=yyyyyy

use rs("xxxxxx")=yyyyyy



Also, make sure your data types match. I see that you have dbtext for the field data types in the tabledef, but you use dbl in the values?



Finally, I don't think you need to add the db.CreateTableDef statement in the second part of the code. I just finished an app that created a table in an Access 2000 db and filled it with info from acad.



HTH



Dan
0 Likes
Message 5 of 8

Anonymous
Not applicable

style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I'm having trouble with this line:

Set rs = db.OpenRecordset("SELECT * FROM  '"
& sst & "'")

 

If I hard code it:

'Set rs = db.OpenRecordset("select * from
tettt")

 

It writes, the former does not.  Surely one
can use a variable in an SQL statement?  Perhaps the syntax is
wrong.  Any ideas?

 

 

Public Sub coordadd()
Dim db As
DAO.Database
Dim rs As DAO.Recordset
Dim sst As String
Dim vartest As
Variant
''''''''''''''''''''''''''''''''''("SELECT * FROM '" & strName
& "'")
sst = "tettt"
vartest = "russ"
MsgBox ("SELECT *
FROM  '" & sst & "'")
Set db =
OpenDatabase("C:\Aplace\Databases\yeah.mdb")
Set rs =
db.OpenRecordset("SELECT * FROM  '" & sst & "'")
'Set rs =
db.OpenRecordset("select * from
tettt")
'db.CreateTableDef
rs.AddNew
rs.Fields("Section").Value =
Strsec
rs.Fields("startX").Value = Dblstx
rs.Fields("startY").Value =
Dblsty
rs.Fields("endX").Value = Dblepx
rs.Fields("endY").Value =
Dblepy
rs.Update
rs.Close
db.Close
End Sub

 

Thanks,

 

r

 

Try
this:

Instead of rs.Fields("xxxxxx").Value=yyyyyy
use
rs("xxxxxx")=yyyyyy

Also, make sure your data types match. I see that
you have dbtext for the field data types in the tabledef, but you use dbl in
the values?

Finally, I don't think you need to add the
db.CreateTableDef statement in the second part of the code. I just finished an
app that created a table in an Access 2000 db and filled it with info from
acad.

HTH

Dan
0 Likes
Message 6 of 8

Anonymous
Not applicable
I think that the problem is not the fact that you use a variable, but the
extra set of single quotes.

Try: Set rs = db.OpenRecordset("SELECT * FROM " & sst )

James
0 Likes
Message 7 of 8

Anonymous
Not applicable
This code will write to a data base. When I try and use a variable it
doesn't write. That's the only thing I can think of. Also, the '.value'
property doesn't seem to be a problem.
Possibly it could be something with creating a table and then using .addnew
method... i don't know at this time.



Public Sub coordadd()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Tdf As TableDef
Dim prploop As Property
Dim strName As String
Dim state As AcadState
Set db = OpenDatabase("C:\Aplace\Databases\yeah.mdb")
Set rs = db.OpenRecordset("tettt")
'Debug.Print rs.Name
'db.CreateTableDef
'rs.MoveFirst
rs.AddNew
rs.Fields("Section").Value = Strsec
rs.Fields("startX").Value = Dblstx
rs.Fields("startY").Value = Dblsty
rs.Fields("endX").Value = Dblepx
rs.Fields("endY").Value = Dblepy
rs.Update
rs.Close
db.Close
End Sub
"James Belshan" wrote in message
news:5FCD802707D1973522506BD9376F22F3@in.WebX.maYIadrTaRb...
> I think that the problem is not the fact that you use a variable, but the
> extra set of single quotes.
>
> Try: Set rs = db.OpenRecordset("SELECT * FROM " & sst )
>
> James
>
>
>
0 Likes
Message 8 of 8

Anonymous
Not applicable
I got it working. I needed to change the sql statement as suggested and
also use an input box. It works. Gracias. Suggestions are still welcome.


"RHeldt" wrote in message
news:5F1030128A27D4B00B3F84712A20D658@in.WebX.maYIadrTaRb...
> This code will write to a data base. When I try and use a variable it
> doesn't write. That's the only thing I can think of. Also, the '.value'
> property doesn't seem to be a problem.
> Possibly it could be something with creating a table and then using
.addnew
> method... i don't know at this time.
>
>
>
> Public Sub coordadd()
> Dim db As DAO.Database
> Dim rs As DAO.Recordset
> Dim Tdf As TableDef
> Dim prploop As Property
> Dim strName As String
> Dim state As AcadState
> Set db = OpenDatabase("C:\Aplace\Databases\yeah.mdb")
> Set rs = db.OpenRecordset("tettt")
> 'Debug.Print rs.Name
> 'db.CreateTableDef
> 'rs.MoveFirst
> rs.AddNew
> rs.Fields("Section").Value = Strsec
> rs.Fields("startX").Value = Dblstx
> rs.Fields("startY").Value = Dblsty
> rs.Fields("endX").Value = Dblepx
> rs.Fields("endY").Value = Dblepy
> rs.Update
> rs.Close
> db.Close
> End Sub
> "James Belshan" wrote in message
> news:5FCD802707D1973522506BD9376F22F3@in.WebX.maYIadrTaRb...
> > I think that the problem is not the fact that you use a variable, but
the
> > extra set of single quotes.
> >
> > Try: Set rs = db.OpenRecordset("SELECT * FROM " & sst )
> >
> > James
> >
> >
> >
>
>
0 Likes