Solved

Programming MSAccess with VB

Posted on 2002-05-31
8
295 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now