Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / December 2005

Tip: Looking for answers? Try searching our database.

Export MS Access table via OBDC using VB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rjgst3 - 17 Dec 2005 15:36 GMT
I'm trying to export a reference table from MS Access to a table via
ODBC.  Is there a way I can use a DAO.Recordset and use the
value(field) to populate my ODBC table?

Dim rs as DAO.Recordset
Dim conn as New ADODB.Connection
Dim strsql as String

Set rs = CurrentDb.OpenRecordset("select field1, field2, field3,
field4, field5.....from daotable").Openrecordset
Move.First

strsql = "insert into odbctable rs.value(field1, field2, field3,
field4, field5.....)

conn.ConnectionString = "dsn=Database ; uid=UID; pwd=password"
conn.ConnectionTimeout = 0
conn.CommandTimeout = 0
conn.Open

Do
conn.Execute (strsql)
rs.MoveNext
Loop Unit rs.EOF

conn.close
Terry Kreft - 17 Dec 2005 19:35 GMT
It goes something like

Dim rs as DAO.Recordset
Dim conn as New ADODB.Connection
Dim strsql as String

Set rs = CurrentDb.OpenRecordset("select field1, field2, field3,
field4, field5.....from daotable")

conn.ConnectionString = "dsn=Database ; uid=UID; pwd=password"
conn.ConnectionTimeout = 0
conn.CommandTimeout = 0
conn.Open

with rs
   do until .eof
       strsql = "insert into odbctable ( F1, F2, F4, F4, F5) " _
                & "VALUES (" & .Fields("field1") & ", " .Fields("field2") _
               & ", " & .Fields("field3") & ", " & .Fields("field4" _
               & ", " & .Fields("field5") & ")"

       conn.execute strsql
       .movenext
   loop
end with
conn.close

' etc...

You'll need t insert single quotes (') in their as well if the fields are
strings.

Signature

Terry Kreft

> I'm trying to export a reference table from MS Access to a table via
> ODBC.  Is there a way I can use a DAO.Recordset and use the
[quoted text clipped - 22 lines]
>
> conn.close
Bri - 17 Dec 2005 21:51 GMT
> I'm trying to export a reference table from MS Access to a table via
> ODBC.  Is there a way I can use a DAO.Recordset and use the
[quoted text clipped - 22 lines]
>
> conn.close

AIRCODE based on your sample code
=======

Dim rs as DAO.Recordset
Dim conn as New ADODB.Connection
Dim strsql as String

Set rs = CurrentDb.OpenRecordset("select field1, field2, field3,
field4, field5.....from daotable").Openrecordset
Move.First

conn.ConnectionString = "dsn=Database ; uid=UID; pwd=password"
conn.ConnectionTimeout = 0
conn.CommandTimeout = 0
conn.Open

Do
INSERT INTO Member ( MemberID, [CCA-ID] )
SELECT Member.MemberID, Member.[CCA-ID]
FROM Member;

strsql = "insert into odbctable (field1, field2, field3)" & _
         "Values (" & rs("field1") & ", " & rs("field2") & _
         ", " & rs("field3") & ") "

conn.Execute (strsql)
rs.MoveNext
Loop Unit rs.EOF

conn.close

END AIRCODE

--
Bri
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.