Solved

Programming MSAccess with VB

Posted on 2002-05-31
8
298 Views
Last Modified: 2012-06-27
Hi there.

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

Thanks in advance,
Luis Mira.
0
Comment
Question by:lmira
8 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7047485
What exactly are you trying to Export?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 7047669
listening
0
 
LVL 7

Expert Comment

by:Joe_Griffith
ID: 7047684
What is an Access Export Specification?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Accepted Solution

by:
vbDoc earned 230 total points
ID: 7047717
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
                                 SysImexColumns
 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
0
 
LVL 4

Expert Comment

by:RichW
ID: 7048153
' 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
objAccess.OpenCurrentDatabase(strPathToMDB)

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

' Clean up
objAccess.CloseCurrentDatabase
ObjAccess.Quit
Set objAccess = Nothing
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7048297
learning...
0
 

Author Comment

by:lmira
ID: 7050711
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"
    x.CloseCurrentDatabase
    x.Quit
    Set x = Nothing
End Sub
***********************************************************
0
 

Author Comment

by:lmira
ID: 7050719
I don't know if the answer was realy accepted, so here it goes again.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question