• Home
  • Blog
  • Resume
  • Contact
  • Projects
  • Gallery
  • Amit’s Resume
  • About Nagpur
KEEP IN TOUCH

Access VBA: Export Access tables using ODBC

Jul18
2007
3 Comments Written by admin

If you want to export Access tables using ODBC/DSN connections, use the following code. This procedure uses the File DSN and ODBC connection to export Access tables using DAO object TableDef.

Sub ExportTbls()

Dim sTblNm As String
Dim sTypExprt As String
Dim sCnxnStr As String, vStTime As Variant
Dim db As Database, tbldef As DAO.TableDef

On Error GoTo ExportTbls_Error

sTypExprt = “ODBC Database” ‘Export Type
sCnxnStr = “ODBC;DSN=DSNName;UID=userID;PWD=password” ‘Create the connection string

vStTime = Timer
Application.Echo False, “Visual Basic code is executing.”

Set db = CurrentDb()

‘need a reference to Microsoft DAO 3.x library
For Each tbldef In db.TableDefs
‘Don’t export System and temporary tables
If Left(tbldef.Name, 4) “MSys” And Left(tbldef.Name, 4) “~TMP” Then
‘Debug.Print tbldef.Name
sTblNm = tbldef.Name
DoCmd.TransferDatabase acExport, sTypExprt, sCnxnStr, acTable, sTblNm, sTblNm
End If
Next tbldef

MsgBox “Done! Time taken=” & Timer – vStTime

On Error GoTo 0
SmoothExit_ExportTbls:
Set db = Nothing
Application.Echo True
Exit Sub

ExportTbls_Error:
MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) in procedure ExportTblsODST”
Resume SmoothExit_ExportTbls
End Sub

Related posts:

  1. Access VBA: Delete tables from Access database
  2. Access VBA: Link all Dbase files from a folder
  3. Range Concatenation with a character
  4. Stack Columns of Data on one column
Posted in Access, Useful Procedures - Tagged Access, ODBC, VBA
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Access VBA: Delete tables from Access database
» Access VBA: Convert Access tables to arff format

3 Comments

  1. n8_Mills's Gravatar n8_Mills
    August 25, 2011 at 6:28 pm | Permalink

    http://nandeshwar.info/wp-comments-post.php

    Thanks, this saved me a pantload of time. However, the copy/paste wasn’t all that friendly, I had to do a find/replace on all the quotes and commas since they aren’t the same as the VBA IDE. Also, “If Left(tbldef.Name, 4) “MSys” And Left(tbldef.Name, 4) “~TMP” Then” is missing the “not equals” signs, it should be:

    If Left(tbldef.Name, 4) “MSys” And Left(tbldef.Name, 4) “~TMP” Then

    Hopefully you can repost with these changes so more noobish peeps can find it useful.

    Best,

    n8

  2. n8_Mills's Gravatar n8_Mills
    August 25, 2011 at 6:29 pm | Permalink

    Interestingly, even my posts change the quotes and “equals” / “not equals” signs. Something about this web site is very VBA un-friendly.

  3. a7n9's Gravatar a7n9
    August 29, 2011 at 9:33 pm | Permalink

    Sorry, n8, I did not update the code after I changed the encoding of the VBA code. I will edit those soon. Thanks for the heads up.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Tags

Access Alt F8 Books boxplot cells charts count cursor dashboard data mining dbase design error excel excel functions export filter flip LaTex MS query Number Err ODBC pipes Press Alt F11 Public Sub python R random numbers Range Cells report scripting software sparklines SQL SQL server stack columns statistics stemming string tag cloud text mining UDF VBA visualization wildcard

Network

View Ashutosh Nandeshwar's profile on LinkedIn

Recent Comments

  • W. McNabb on The search key was not found in any record in Access
  • Manuel on The search key was not found in any record in Access
  • Wendy Naples on The search key was not found in any record in Access
  • larry on Access Export to Excel (2007)
  • Betty Chou on Projects

Related Posts

  1. Access VBA: Delete tables from Access database
  2. Access VBA: Link all Dbase files from a folder
  3. Range Concatenation with a character
  4. Stack Columns of Data on one column

EvoLve theme by Blogatize  •  Powered by WordPress nandeshwar.info