Solved

Programming MSAccess with VB

Posted on 2002-05-31
8
297 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 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