Does anyone know how can I import a qif file (old Quicken format for bank
statements, which is the one still used from my online bank) into an MS
Access table?
I have some knowledge of VBA, so I believe I could write the code to get it
done but I imagine something already exits. (Althought Goggleing it gave no
results).
Thanks in advance.
Alberto
I just needed this myself and could not find it anywhere.
here tis - you will need to change the path for saving your file
Sub ExportToQIF()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strFilePath As String
Dim strQIF As String
Dim strDate As String
Dim strDescription As String
Dim strAmount As String
Dim strTableName As String
Dim intFileNum As Integer
' Prompt the user for the table name
strTableName = InputBox("Enter the name of the table to export:", "Table Name")
' Check if the user entered a table name
If strTableName = "" Then
MsgBox "No table name entered. Export cancelled.", vbExclamation
Exit Sub
End If
' Set the file path for the QIF file
strFilePath = "C:\Users\judyb\OneDrive\Documents\Private\file.qif"
' Open the recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT Date, Description, Amount FROM [" & strTableName & "]")
' Initialize the QIF string
strQIF = "!Type:Bank" & vbCrLf
' Loop through the records and build the QIF string
Do While Not rs.EOF
strDate = Format(rs("Date"), "mm/dd/yyyy")
strDescription = rs("Description")
strAmount = Format(rs("Amount"), "0.00")
strQIF = strQIF & "D" & strDate & vbCrLf
strQIF = strQIF & "T" & strAmount & vbCrLf
strQIF = strQIF & "P" & strDescription & vbCrLf
strQIF = strQIF & "^" & vbCrLf
rs.MoveNext
Loop
' Close the recordset
rs.Close
Set rs = Nothing
Set db = Nothing
' Write the QIF string to the file
On Error GoTo ErrorHandler
intFileNum = FreeFile
Open strFilePath For Output As #intFileNum
Print #intFileNum, strQIF
Close #intFileNum
MsgBox "Export to QIF completed successfully!", vbInformation
Exit Sub
ErrorHandler:
MsgBox "Error: " & Err.Description, vbCritical
If intFileNum > 0 Then Close #intFileNum
End Sub