I have added DoCmd.Close acQuery, "Import", acSaveNo
And my access window doesn't close even with this line of code.
Option Compare Database
Option Explicit
Public Function Import()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim intFile As Integer
Dim strFilePath As String
Dim intCount As Integer
Dim strHold
strFilePath = "C:\Transfer\FromSynapseTest\TEST.csv"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Import", dbOpenForwardOnly)
intFile = FreeFile
Open strFilePath For Output As #intFile
Do Until rst.EOF
If CDate(rst(3)) >= Date And rst(98) <> 0 Then
For intCount = 0 To rst.Fields.Count - 1
strHold = strHold & rst(intCount).Value & "|"
Next
If Right(strHold, 1) = "|" Then
strHold = Left(strHold, Len(strHold) - 1)
End If
Print #intFile, strHold
End If
rst.MoveNext
strHold = vbNullString
Loop
Close intFile
rst.Close
Set rst = Nothing
DoCmd.Close acQuery, "Import", acSaveNo
End Function
Since I'm calling the function by macro, I don't think I can do
Sub subToCloseForm
DoCmd.Close
End Sub
Also I have tried DoCmd.Close acQuery, " ", acSaveNo
based on what I read http://www.blueclaw-db.com/docmd_close_example.htm : If you leave the objecttype and objectname arguments blank (the default constant, acDefault, is assumed for objecttype), Microsoft Access closes the active window
Any help would be greatly appreciated. Thank you.