Code:
Dim EF As Integer 'errors file
EF = FreeFile
str = DLookup("LastFileImported", "tblImportFileName")
pos_slash = InStrRev(str, "\")
pos_dot = InStrRev(str, ".")
FileToWrite = Mid(str, pos_slash + 1, pos_dot - pos_slash)
FileToWrite = CurrentProject.Path & "\ERRORS_" & FileToWrite & "_ImportEmp" & ".txt"
Open FileToWrite For Output As #EF
'print header text
Print #EF, "EmpID, SSN, LName, FName, Old Fringe Rate, New Fringe Rate, Change Date"
'static text
Print #EF, "ERROR- Invalid SSN "
' error data
Print #EF, vEID & ", " & vSSN & ", " & vLast & ", " & vFirst
' print blank line
Print #EF,
' close and save text file
Close #EF