Question : Append.dif file to Access 2007 table

My business system exports data to a .dif file.  I am able to open the .dif file in excel and everything is properly formatted.

I am trying to append this .dif file to an Access 2007 table.  The import wizzard does not recognize .dif files.

The source is parts.dif    and the Access table is tblParts.

Is there a VB code to append a .dif file to a table?

Answer : Append.dif file to Access 2007 table

These are the steps required:

On your Form, make a command button called cmd_ReadExcel
copy and paste the code below, in your VBA.

what this will do:
1. it open excel in a hidden mode,
2. it will read the file C:\Parts.dif,
3. it will delete the first row of it (this is the column names),
4. it will save this file to C:\Parts.csv (which Access can read and import),

This next part is, the code will call an append query code:
call MaintainTransactionData
BUT you will have to modify the code, with the correct Table name, and the field names (if you already have an append query ready, go to view > SQL, and you can copy the SQL Append query code).

Please note the field names, table name, and the path of C;\Parts.dif

good luck in your program :)

jaffer
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
Private Sub cmd_ReadExcel_Click() 
Dim oApp1 As Object 'Excel.Application  'Object 
Set oApp1 = CreateObject("Excel.Application")
oApp1.workbooks.Open "C:\Parts.dif"
'oApp1.Visible = True
oApp1.Rows("1:1").Select
oApp1.Selection.Delete Shift:=xlUp
oApp1.ActiveWorkbook.SaveAs Filename:="C:\Parts.csv", FileFormat:=xlCSV
oApp1.ActiveWorkbook.Close SaveChanges:=False
oApp1.Application.Quit
Set oApp1 = Nothing 
call MaintainTransactionData
End Sub 
Public Sub MaintainTransactionData()
    'from
    'http://www.utteraccess.com/forums/printthread.php?Cat=&Board=84&main=1694936&type=thread
    
    Dim db As DAO.Database
    Dim strSQL As String
    
    'Set a reference to the current db
    Set db = CurrentDb
    
    'Append from CSV ...
    strSQL = "INSERT INTO tblSomeTable ( [TRADE DATE], REP, REPID, [ACCOUNT/POLICY]," & _
                                       " CUSTOMER, [REP# COMPANY], [PRODUCT NAME]," & _
                                       " QUANTITY, [FACE AMOUNT], [GROSS COMMISSION]," & _
                                       " [CUSTOMER SSN] )" & _
             " SELECT [TRADE DATE], REP, REPID, [ACCOUNT/POLICY]," & _
                    " CUSTOMER, [REP# COMPANY], [PRODUCT NAME]," & _
                    " QUANTITY, [FACE AMOUNT], [GROSS COMMISSION]," & _
                    " [CUSTOMER SSN]" & _
             " FROM [Text;FMT=Delimited;HDR=YES;CharacterSet=437;" & _
                   " DATABASE=C:\Parts.csv"
    
    db.Execute strSQL, dbFailOnError
    
End Sub
Random Solutions  
 
programming4us programming4us