Solved

Programming MSAccess with VB

Posted on 2002-05-31
8
299 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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