• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Programming MSAccess with VB

Hi there.

Any one knowns how to create Access Export Specifications programmatically with Visual Basic 6?

Thanks in advance,
Luis Mira.
1 Solution
What exactly are you trying to Export?
What is an Access Export Specification?
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Import/Export Specifications and CommandBars travel with the database they were created in.  That is, all the information about them is stored in hidden, system tables whose names are as follows:

 Information Type System         Table Name
 -----------------------         ----------
 Import/Export Specifications    MSysImexSpecs and
 CommandBars                     MSysCmdBars

While you
can't edit these tables through the datasheet view, you can modify (and delete) from code.

Sub DeleteImpExp() Dim db As DAO.Database Dim strSQL As String Set db = CurrentDb strSQL = "Delete *
from MSysIMEXColumns"
db.Execute strSQL, dbFailOnError strSQL = "Delete * from MSysIMEXSpecs"
dc.Execute strSQL, dbFailOnError End Sub
' This code will do an output to HTML

Dim objAccess
Dim strPathToMDB
Dim strTableName
Dim strFilePath

Const acImportDelim = 0
Const acFormatHTML = "HTML (*.html)"
Const acOutputTable = 0

'  The following 3 lines of code are the only variables that need be edited
'  Provide paths to the Access MDB, Text file for import and the new table name.
strPathToMDB = "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb"
strFilePath = "C:\CustomerList.htm"
strTableName = "Customers"

' Create Access 97 Application Object
Set objAccess = CreateObject("Access.Application.8")

' For Access 2000, use Application.9
'Set objAccess = CreateObject("Access.Application.9")

' Open the desired database

' Use the TransferText command to import the file (with Column Heads)
objAccess.DoCmd.OutputTo acOutputTable, strTableName, acFormatHTML, strFilePath, True

' Clean up
Set objAccess = Nothing
Richie_SimonettiIT OperationsCommented:
lmiraAuthor Commented:
Thanks vbDoc.
That was a good tip that took me into a solution to solve my problem. I didn't knew the MSysIMEXSpecs table until now.
Here is a word to RichW:
I already have done that but with TransferText method that allows me format the output file (with field separators, for instance) and that method needs an export specification.
With this export file I can now do a BulkInsert in SQL Server.

For those who are interested in the solution here it is:

Private Sub Command1_Click()
Dim x As New Access.Application
Dim SQLStatement As String

    x.OpenCurrentDatabase "c:\bd.mdb"
    SQLStatement = "insert into MSysImexSpecs (DateDelim,DateFourDigitYear,DateLeadingZeros,DateOrder,DecimalPoint,FieldSeparator,FileType,SpecName,SpecType,StartRow,TextDelim,TimeDelim) " & _
                    "values ('-','0','0','0','.','|','0','JournalExpSpec','1','0','',':')"
    x.DoCmd.RunSQL SQLStatement, True
    x.DoCmd.TransferText acExportDelim, "JournalExpSpec", "Journal", "journal.txt"
    Set x = Nothing
End Sub
lmiraAuthor Commented:
I don't know if the answer was realy accepted, so here it goes again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now