Kbase 19442: How to Import Data into an Access Database from a delimited text file
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  15/10/2008 |
|
Status: Verified
GOAL:
How to import data into Microsoft Access from a delimited text file.
FACT(s) (Environment):
Microsoft Access 97.
FIX:
Before you run the piece of code, complete the following steps:
1) Create a MS Access database "myDb.mdb".
2) Create a table "myTable".
3) Add these fields in "myTable":
- "Description": Text (default size)
- "Language": Text (default size)
4) Create a Text file named "Data.txt".
5) Add the following data to "Data.txt":
- "Description","Language"
- "Bonjour", "French"
- "Good morning", "English"
- "Goedemorgen", "Dutch"
- "Manao ahoana", "Malagasy"
The following is the code:
/* ********************* Definitions ***************************** */
DEFINE BUTTON cmdOLE
LABEL "&OLE"
SIZE 15 BY 1.14.
DEFINE FRAME frmMain
cmdOLE AT ROW 2 COL 5
WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
SIDE-LABELS NO-UNDERLINE THREE-D
AT COL 1 ROW 1
SIZE 25 BY 4.
/* ******************** Trigger *********************************** */
ON CHOOSE OF cmdOLE IN FRAME frmMain /* Start MS Access */
DO:
DEF VAR hAccess AS COM-HANDLE NO-UNDO.
CREATE "Access.Application.8" hAccess CONNECT TO "c:\temp\mydb.mdb".
hAccess:Application:docmd:TransferText(0,,"MyTable",
"C:\temp\data.txt",true,).
RELEASE OBJECT hAccess.
END.
DO ON ERROR Undo, leave ON END-KEY undo, leave:
DISPLAY cmdOLE WITH FRAME frmMain.
ENABLE cmdOLE WITH FRAME frmMain.
WAIT-FOR CLOSE OF THIS-PROCEDURE.
END.