Вывод в файл в UTF-8 |
Private Sub button01_Click() 'delete old filedata Call ClearTablesRef 'link new file Call LinkSchema ' End Sub Function LinkSchema() Dim db As Database, tbl As TableDef, filename As String, rst As Recordset, arr() Set db = CurrentDb() Set tbl = db.CreateTableDef("SourceData") ' Append selection of any file through a dialog box filename = "Asci.txt" Call SchemaIniCreate(filename) ' Connect to the data source file tbl.Connect = "Text;DATABASE=" & CurrentProject.Path & ";TABLE=" & filename & "" tbl.SourceTableName = filename With db.TableDefs .Append tbl .Refresh End With ' Find error in file strSql = "SELECT SourceData.pid, SourceData.Sname, SourceData.Fname, SourceData.fday " & _ "FROM SourceData GROUP BY SourceData.pid, SourceData.Sname, SourceData.Fname, SourceData.fday " & _ "HAVING ((Count(*) Mod 2)=1)" Set rst = db.OpenRecordset(strSql) If rst.RecordCount > 0 Then Call ErrLogCreate(funMsgListRecord(strSql)) Call MsgBox("Import with errors!", vbCritical, "ERRORS!") End If End Function ' Create schema.ini for .csv or .txt file ' If the column names, number of columns, or type columns of data will be changed - edit this part of the code. Function SchemaIniCreate(filename As String) Dim create_file_name As String create_file_name = CurrentProject.Path & "\schema.ini" Open create_file_name For Output As #1 Print #1, "[" & filename & "]" Print #1, "Format = Delimited(;)" 'IN USE. Use only one! 'Print #1, "Format = Delimited(,)" 'Use only one! Print #1, "MaxScanRows = 0" Print #1, "ColNameHeader = False" Print #1, "CharacterSet = 65001" Print #1, "DecimalSymbol = ." Print #1, "CurrencyDecimalSymbol = ." Print #1, "Col1=""ouid"" Long Width 10" Print #1, "Col2=""did"" Long Width 10" Print #1, "Col3=""pid"" Long Width 10" Print #1, "Col4=""fday"" DateTime Width 30" Print #1, "Col5=""ftime"" DateTime Width 30" Print #1, "Col6=""punch"" Byte Width 3" Print #1, "Col7=""Sname"" Char Width 100" Print #1, "Col8=""Fname"" Char Width 100" Close #1 End Function ' Create Error Description Function funMsgListRecord(ByVal sSQL As String) Dim rst As DAO.Recordset Dim sListMsg As String Dim Output As String On Error GoTo Err_ Set rst = CurrentDb.OpenRecordset(sSQL, dbOpenSnapshot) With rst If Not (.BOF And .EOF) Then .MoveLast .MoveFirst Do Until .EOF If sListMsg = "" Then Output = "id:" & !PID & ", Name: " & !Sname & " " & !fname & ", Date:" & !fDay & "" sListMsg = Output Else Output = "id:" & !PID & ", Name: " & !Sname & " " & !fname & ", Date:" & !fDay & "" sListMsg = sListMsg & ""
& vbCrLf & Output End If .MoveNext Loop End If .Close End With Set rst = Nothing funMsgListRecord = sListMsg Exit Function Err_: MsgBox Err.Description Err.Clear End Function ' Create errorlog.html if .csv or .txt contain error Function ErrLogCreate(errmsg As String) Dim errorlog As String errorlog = CurrentProject.Path & "\errorlog.html" Open errorlog For Output As #2 Print #2, "" Print #2, "Errors in the import file:
" Print #2, "" & errmsg & "
" Print #2, "" Close #2 End Function
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |