How to Import Text File into Microsoft Access Table Using DDE
ID: Q113905
|
The information in this article applies to:
-
Microsoft Visual Basic Professional and Enterprise Editions, 16-bit only, for Windows, version 4.0
-
Microsoft Visual Basic Standard and Professional Editions for Windows, version 3.0
SUMMARY
This article shows you how to implement the built-in TransferText command
of Microsoft Access to import data from a text file into a Microsoft Access
Table using DDE. This method is faster than the alternate method outlined
in the following article in the Microsoft Knowledge Base:
Q103807
: How to Convert a Text File into a New Access Database
MORE INFORMATION
The TransferText command is used in Access Basic to import data from a text
file into a table. If the table specified doesn't exist, the TransferText
command creates the table. If the table does exist, the text file's format
must match that of the existing table.
The text file can be comma delimited with strings enclosed in quotation
marks or it can be of fixed width. The delimiter and fixed width settings
can be set up in Microsoft Access by choosing Imp/Exp Setup from the File
menu. For more information on these settings, please consult the Microsoft
Access Help menu.
Step-by-Step Example
- Using Notepad, create the following file to import and save it as
C:\ACCESS\SHIPPERS.TXT:
4,"world traveller"
5,"frazier freight"
6,"longfellow hauling"
7,"toolsmith shipping"
- Start Microsoft Access and open the C:\ACCESS\NWIND.MDB database.
- Start a new project in Visual Basic (ALT, F, N). Form1 is created by
default.
- Place a text box (Text1) and a command button (Command1) on the form.
- Add the following code to the click event of Command1:
Sub Command1_Click ()
Dim cmd As String ' Holds DDEExecute command.
On Error GoTo DDEerr ' Error trap.
' Make sure there isn't an existing DDE conversation:
text1.LinkMode = 0
' Set up the DDE link:
text1.LinkTopic = "MSACCESS|C:\ACCESS\NWIND.MDB"
text1.LinkItem = "All"
text1.LinkMode = 2
' DDEExecute command to import text file into Microsoft Access Table:
cmd = "[TransferText ,,'Shippers','C:\ACCESS\SHIPPERS.TXT']"
' Execute the TransferText command and close the DDE link:
text1.LinkExecute cmd
text1.LinkMode = 0
MsgBox "Transfer OK"
Exit Sub
DDEerr:
' An error has occurred.
MsgBox Error
MsgBox "Error in transfer."
Exit Sub
End Sub
- Run the Visual Basic program and click the command button to import the
information in the text file into the Shippers table. A message box will
be displayed showing you whether or not the transfer was successful.
For more information on how to implement DDE with Microsoft Access, please
see the following article in the Microsoft Knowledge Base:
Q96845
: How to Use DDE to Display Microsoft Access Data in VB
Additional query words:
3.00 4.00 vb416
Keywords : kbcode IAPDDE
Version : 3.00 4.00
Platform : WINDOWS
Issue type :
|