Saving data to MDB from AutoCAD VBA

Saving data to MDB from AutoCAD VBA

Anonymous
Not applicable
1,185 Views
5 Replies
Message 1 of 6

Saving data to MDB from AutoCAD VBA

Anonymous
Not applicable
Can anyone point me to some sample code / help for
reading and writing to an Access MDB from an
AutoCAD VBA module?

Thanks for any help.

Tom Yacomeni
0 Likes
1,186 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Do a search for ADO from google. You should get alot of hits from sites
that have basic tutorials on accessing an Access database.

Heres a Start;
(must have a reference set to MS ActiveX Data Objects)
Dim DB As ADODB.Connection
Dim RS As ADODB.Recordset

Set DB = New ADODB.Connection
Set RS = New ADODB.Recordset

'Open a Database connection
DB.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\MyDatabase.mdb;" & _
"Jet OLEDB:Database Password=MyPassword;"

'Open a recordset
With RS
.ActiveConnection = DB
.CursorLocation = adUseClient
.LockType = adLockOptimistic

.Open "SELECT * FROM MyTableName"
End With

'Navigate through the records
With RS
.MoveFirst
Do Until .EOF
Debug.Print RS!MyFieldName

.MoveNext

Loop
End With

'Destroy objects
Set DB = Nothing
Set RS = Nothing

--
Veign
www.veign.com
VB Code Samples & Projects
www.veign.com/information/info_main.html
<-- Submit Your Favorite Code and get published! -->
www.veign.com/information/application/code_submit.html




"tom.yacomeni" wrote in message
news:f0c03bf.-1@WebX.maYIadrTaRb...
> Can anyone point me to some sample code / help for
> reading and writing to an Access MDB from an
> AutoCAD VBA module?
> Thanks for any help.
>
> Tom Yacomeni
>
>
Message 3 of 6

Anonymous
Not applicable
Thanks for the quick reply - I'll have a go.
I have to admit though I'm more used to
programming DAO inside Access rather than ADO.
Is that just as easy to implement externally?
Thanks
Tom
0 Likes
Message 4 of 6

Anonymous
Not applicable
I'm not familiar with using DAO 'inside' Access, but I
know you can still use DAO, if that's what you're used to.  It was
recommended to me to use ADO, but I'm not knowledgeable enough to say why or if
it was good advice.

 

I've been quite successful using VBA/ADO without much
experience with either one.


style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
Thanks
for the quick reply - I'll have a go.
I have to admit though I'm more used
to
programming DAO inside Access rather than ADO.
Is that just as easy
to implement externally?
Thanks
Tom
0 Likes
Message 5 of 6

Anonymous
Not applicable
It's usually a good idea to add to the connection string:

"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\MyDatabase.mdb;" & _
"Jet OLEDB:Database Password=MyPassword;" & _
"Persist Security Info-False"

--
jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services

In article <253BF8609D8A4D34BF7AF2D8ACD19D07@in.WebX.maYIadrTaRb>, Veign
wrote:
> Do a search for ADO from google. You should get alot of hits from sites
> that have basic tutorials on accessing an Access database.
>
> Heres a Start;
> (must have a reference set to MS ActiveX Data Objects)
> Dim DB As ADODB.Connection
> Dim RS As ADODB.Recordset
>
> Set DB = New ADODB.Connection
> Set RS = New ADODB.Recordset
>
> 'Open a Database connection
> DB.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=C:\MyDatabase.mdb;" & _
> "Jet OLEDB:Database Password=MyPassword;"
>
> 'Open a recordset
> With RS
> .ActiveConnection = DB
> .CursorLocation = adUseClient
> .LockType = adLockOptimistic
>
> .Open "SELECT * FROM MyTableName"
> End With
>
> 'Navigate through the records
> With RS
> .MoveFirst
> Do Until .EOF
> Debug.Print RS!MyFieldName
>
> .MoveNext
>
> Loop
> End With
>
> 'Destroy objects
> Set DB = Nothing
> Set RS = Nothing
>
> --
> Veign
> www.veign.com
> VB Code Samples & Projects
> www.veign.com/information/info_main.html
> <-- Submit Your Favorite Code and get published! -->
> www.veign.com/information/application/code_submit.html
>
>
>
>
> "tom.yacomeni" wrote in message
> news:f0c03bf.-1@WebX.maYIadrTaRb...
> > Can anyone point me to some sample code / help for
> > reading and writing to an Access MDB from an
> > AutoCAD VBA module?
> > Thanks for any help.
> >
> > Tom Yacomeni
> >
> >
>
0 Likes
Message 6 of 6

Anonymous
Not applicable
DAO is obsolescent; it still exists, but is not supported and has not
been updated for a few years. You can use DAO externally.

ADO is easier than DAO (all other things being equal; if you're already
a DAO expert you need a little learning to use ADO) and is more
powerful and robust.

--
jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services

In article , Tom.yacomeni wrote:
> Thanks for the quick reply - I'll have a go.
> I have to admit though I'm more used to
> programming DAO inside Access rather than ADO.
> Is that just as easy to implement externally?
> Thanks
> Tom
>
0 Likes