StampIT
asked on
How to process file data into Access
The attached file is created by our ERP application. Each file is a record. Each row is a field. The rows are divided by a comma. The text before the comma is the field name. The text after is the data. The ultimate goal is to write the data into an Access table.The field names in the Access table are the same as those in the file. Each file is written to a folder. The folder needs to be monitored so files can be processed as soon as they are created and then archived. A bar code label program prints a label using the data in the Access table.
My idea was to use a SQL integration Services package to monitor the folder and import the contents of each file to the Access table or to a SQL table and then to the Access table. Is it possible to process the files this way in a timely manner ? If so what would be the steps(detail please) to accomplish this ?
Thanks
MKR26-MAR-19095456_Test_EE.pas
My idea was to use a SQL integration Services package to monitor the folder and import the contents of each file to the Access table or to a SQL table and then to the Access table. Is it possible to process the files this way in a timely manner ? If so what would be the steps(detail please) to accomplish this ?
Thanks
MKR26-MAR-19095456_Test_EE.pas
Pat's code should get you started, but before going there - are you sure your ERP system can't give a more standard format, like a CSV dump? I I work with EDI data every day, and that is not a format I've seen before.
This only takes a query to filter the data, if you link the file renamed as a text file (AutoDeereGTL-1.txt):
lwl.accdb
SELECT
[AutoDeereGTL-1].FieldName,
[Data1] & (" "+[Data2]) AS Data
FROM
[AutoDeereGTL-1]
WHERE
Asc([FieldName]) <> 42;
and a few lines of code:Public Function FillTable()
Dim db As DAO.Database
Dim rsSource As DAO.Recordset
Dim rsTarget As DAO.Recordset
Set db = CurrentDb
Set rsSource = db.OpenRecordset("AutoDeereGTL")
Set rsTarget = db.OpenRecordset("AutoDeere")
rsTarget.AddNew
While Not rsSource.EOF
Select Case rsSource!FieldName.Value
Case "ShipDate"
rsTarget(rsSource!FieldName.Value).Value = CDate(Format(rsSource!Data.Value, "@@@@\/@@\/@@"))
Case "Weight"
rsTarget(rsSource!FieldName.Value).Value = Val(rsSource!Data.Value)
Case Else
rsTarget(rsSource!FieldName.Value).Value = rsSource!Data.Value
End Select
rsSource.MoveNext
Wend
rsTarget.Update
End Function
If you don't have the source table, it can be created by this tiny function:Public Function CreateTable()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim td As DAO.TableDef
Dim fd As DAO.Field
Set db = CurrentDb
Set rs = db.OpenRecordset("AutoDeereGTL")
Set td = db.CreateTableDef("AutoDeere")
While Not rs.EOF
Select Case rs!FieldName.Value
Case "ShipDate"
Set fd = td.CreateField(rs!FieldName.Value, dbDate)
Case "Weight"
Set fd = td.CreateField(rs!FieldName.Value, dbCurrency)
Case Else
Set fd = td.CreateField(rs!FieldName.Value, dbText)
End Select
td.Fields.Append fd
rs.MoveNext
Wend
db.TableDefs.Append td
End Function
See the attached demo, which also holds the import specification.lwl.accdb
Here is complete tutorial on the Implementation using SSIS.
If you want to avoid the SSIS overhead you could develop a small .NET application using the FileSystemWatcher class
If you want to avoid the SSIS overhead you could develop a small .NET application using the FileSystemWatcher class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The format of this file is really sloppy. There are spaces after some field names which will interfere with matching them with a column name since spaces are also characters. You can use the Trim() function to strip off leading and trailing spaces and that will also help with the data part of the records. Field values can also contain comas and that will interfere with using the Split() function so since there is in theory only a single data field, you can probably use InStr() instead of Split() (which is what the attached procedure) to find out where the data starts.
I've included some code that imports an EDI file EDI (Electronic Data Interchange) is a transaction format standard agreed to by many companies that allows them to transfer data in a pre-defined, standardized format. The sample code is for an 835 transaction which is used to communicate medical billing information between payers (insurance companies) and providers (doctors, hospitals, etc)
The code is obviously not what you need but it does include all the necessary elements to show you how to import a non-standard file format and load the data into a table. There are comments to explain some of the more strange conditions the code needed to deal with.
Open in new window