VCS_Table.bas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. Attribute VB_Name = "VCS_Table"
  2. Option Compare Database
  3. Option Private Module
  4. Option Explicit
  5. ' --------------------------------
  6. ' Structures
  7. ' --------------------------------
  8. ' Structure to keep track of "on Update" and "on Delete" clauses
  9. ' Access does not in all cases execute such queries
  10. Private Type structEnforce
  11. foreignTable As String
  12. foreignFields() As String
  13. table As String
  14. refFields() As String
  15. isUpdate As Boolean
  16. End Type
  17. ' keeping "on Update" relations to be complemented after table creation
  18. Private K() As structEnforce
  19. Public Sub ExportLinkedTable(ByVal tbl_name As String, ByVal obj_path As String)
  20. On Error GoTo Err_LinkedTable
  21. Dim tempFilePath As String
  22. tempFilePath = VCS_File.TempFile()
  23. Dim FSO As Object
  24. Dim OutFile As Object
  25. Set FSO = CreateObject("Scripting.FileSystemObject")
  26. ' open file for writing with Create=True, Unicode=True (USC-2 Little Endian format)
  27. VCS_Dir.MkDirIfNotExist obj_path
  28. Set OutFile = FSO.CreateTextFile(tempFilePath, overwrite:=True, Unicode:=True)
  29. OutFile.Write CurrentDb.TableDefs(tbl_name).name
  30. OutFile.Write vbCrLf
  31. If InStr(1, CurrentDb.TableDefs(tbl_name).connect, "DATABASE=" & CurrentProject.Path) Then
  32. 'change to relatave path
  33. Dim connect() As String
  34. connect = Split(CurrentDb.TableDefs(tbl_name).connect, CurrentProject.Path)
  35. OutFile.Write connect(0) & "." & connect(1)
  36. Else
  37. OutFile.Write CurrentDb.TableDefs(tbl_name).connect
  38. End If
  39. OutFile.Write vbCrLf
  40. OutFile.Write CurrentDb.TableDefs(tbl_name).SourceTableName
  41. OutFile.Write vbCrLf
  42. Dim Db As DAO.Database
  43. Set Db = CurrentDb
  44. Dim td As DAO.TableDef
  45. Set td = Db.TableDefs(tbl_name)
  46. Dim idx As DAO.Index
  47. For Each idx In td.Indexes
  48. If idx.Primary Then
  49. OutFile.Write Right$(idx.Fields, Len(idx.Fields) - 1)
  50. OutFile.Write vbCrLf
  51. End If
  52. Next
  53. Err_LinkedTable_Fin:
  54. On Error Resume Next
  55. OutFile.Close
  56. 'save files as .odbc
  57. VCS_File.ConvertUcs2Utf8 tempFilePath, obj_path & tbl_name & ".LNKD"
  58. Exit Sub
  59. Err_LinkedTable:
  60. OutFile.Close
  61. MsgBox Err.Description, vbCritical, "ERROR: EXPORT LINKED TABLE"
  62. Resume Err_LinkedTable_Fin
  63. End Sub
  64. ' This requires Microsoft ADO Ext. 2.x for DLL and Security
  65. ' See reference: https://social.msdn.microsoft.com/Forums/office/en-US/883087ba-2c25-4571-bd3c-706061466a11/how-can-i-programmatically-access-scale-property-of-a-decimal-data-type-field?forum=accessdev
  66. Private Function formatDecimal(ByVal tableName As String, ByVal fieldName As String) As String
  67. Dim cnn As ADODB.Connection
  68. Dim cat As ADOX.Catalog
  69. Dim col As ADOX.Column
  70. Set cnn = New ADODB.Connection
  71. Set cat = New ADOX.Catalog
  72. Set cnn = CurrentProject.Connection
  73. Set cat.ActiveConnection = cnn
  74. Set col = cat.Tables(tableName).Columns(fieldName)
  75. formatDecimal = "(" & col.Precision & ", " & col.NumericScale & ")"
  76. Set col = Nothing
  77. Set cat = Nothing
  78. Set cnn = Nothing
  79. End Function
  80. ' Save a Table Definition as SQL statement
  81. Public Sub ExportTableDef(Db As DAO.Database, td As DAO.TableDef, ByVal tableName As String, _
  82. ByVal directory As String)
  83. Dim fileName As String
  84. fileName = directory & tableName & ".sql"
  85. Dim sql As String
  86. Dim fieldAttributeSql As String
  87. Dim idx As DAO.Index
  88. Dim fi As DAO.Field
  89. Dim FSO As Object
  90. Dim OutFile As Object
  91. Dim ff As Object
  92. 'Debug.Print tableName
  93. Set FSO = CreateObject("Scripting.FileSystemObject")
  94. Set OutFile = FSO.CreateTextFile(fileName, overwrite:=True, Unicode:=False)
  95. sql = "CREATE TABLE " & strName(tableName) & " (" & vbCrLf
  96. For Each fi In td.Fields
  97. sql = sql & " " & strName(fi.name) & " "
  98. If (fi.Attributes And dbAutoIncrField) Then
  99. sql = sql & "AUTOINCREMENT"
  100. Else
  101. sql = sql & strType(fi.Type) & " "
  102. End If
  103. Select Case fi.Type
  104. Case dbText, dbVarBinary
  105. sql = sql & "(" & fi.Size & ")"
  106. Case dbDecimal
  107. sql = sql & formatDecimal(tableName, fi.name)
  108. Case Else
  109. End Select
  110. For Each idx In td.Indexes
  111. fieldAttributeSql = vbNullString
  112. If idx.Fields.Count = 1 And idx.Fields(0).name = fi.name Then
  113. If idx.Primary Then fieldAttributeSql = fieldAttributeSql & " PRIMARY KEY "
  114. If idx.Unique Then fieldAttributeSql = fieldAttributeSql & " UNIQUE "
  115. If idx.Required Then fieldAttributeSql = fieldAttributeSql & " NOT NULL "
  116. If idx.Foreign Then
  117. Set ff = idx.Fields
  118. fieldAttributeSql = fieldAttributeSql & formatReferences(Db, ff, tableName)
  119. End If
  120. If Len(fieldAttributeSql) > 0 Then fieldAttributeSql = " CONSTRAINT " & strName(idx.name) & fieldAttributeSql
  121. End If
  122. sql = sql & fieldAttributeSql
  123. Next
  124. sql = sql & "," & vbCrLf
  125. Next
  126. sql = Left$(sql, Len(sql) - 3) ' strip off last comma and crlf
  127. Dim constraintSql As String
  128. For Each idx In td.Indexes
  129. If idx.Fields.Count > 1 Then
  130. If Len(constraintSql) = 0 Then constraintSql = constraintSql & " CONSTRAINT "
  131. If idx.Primary Then constraintSql = constraintSql & formatConstraint("PRIMARY KEY", idx)
  132. If Not idx.Foreign Then
  133. If Len(constraintSql) > 0 Then
  134. sql = sql & "," & vbCrLf & " " & constraintSql
  135. sql = sql & formatReferences(Db, idx.Fields, tableName)
  136. End If
  137. End If
  138. End If
  139. Next
  140. sql = sql & vbCrLf & ")"
  141. 'Debug.Print sql
  142. OutFile.WriteLine sql
  143. OutFile.Close
  144. 'exort Data Macros
  145. VCS_DataMacro.ExportDataMacros tableName, directory
  146. End Sub
  147. Private Function formatReferences(Db As DAO.Database, ff As Object, _
  148. ByVal tableName As String) As String
  149. Dim rel As DAO.Relation
  150. Dim sql As String
  151. Dim f As DAO.Field
  152. For Each rel In Db.Relations
  153. If (rel.foreignTable = tableName) Then
  154. If FieldsIdentical(ff, rel.Fields) Then
  155. sql = " REFERENCES "
  156. sql = sql & strName(rel.table) & " ("
  157. For Each f In rel.Fields
  158. sql = sql & strName(f.name) & ","
  159. Next
  160. sql = Left$(sql, Len(sql) - 1) & ")"
  161. If rel.Attributes And dbRelationUpdateCascade Then
  162. sql = sql + " ON UPDATE CASCADE "
  163. End If
  164. If rel.Attributes And dbRelationDeleteCascade Then
  165. sql = sql + " ON DELETE CASCADE "
  166. End If
  167. Exit For
  168. End If
  169. End If
  170. Next
  171. formatReferences = sql
  172. End Function
  173. Private Function formatConstraint(ByVal keyw As String, ByVal idx As DAO.Index) As String
  174. Dim sql As String
  175. Dim fi As DAO.Field
  176. sql = strName(idx.name) & " " & keyw & " ("
  177. For Each fi In idx.Fields
  178. sql = sql & strName(fi.name) & ", "
  179. Next
  180. sql = Left$(sql, Len(sql) - 2) & ")" 'strip off last comma and close brackets
  181. 'return value
  182. formatConstraint = sql
  183. End Function
  184. Private Function strName(ByVal s As String) As String
  185. strName = "[" & s & "]"
  186. End Function
  187. Private Function strType(ByVal i As Integer) As String
  188. Select Case i
  189. Case dbLongBinary
  190. strType = "LONGBINARY"
  191. Case dbBinary
  192. strType = "BINARY"
  193. Case dbBoolean
  194. strType = "BIT"
  195. Case dbAutoIncrField
  196. strType = "COUNTER"
  197. Case dbCurrency
  198. strType = "CURRENCY"
  199. Case dbDate, dbTime
  200. strType = "DATETIME"
  201. Case dbGUID
  202. strType = "GUID"
  203. Case dbMemo
  204. strType = "LONGTEXT"
  205. Case dbDouble
  206. strType = "DOUBLE"
  207. Case dbSingle
  208. strType = "SINGLE"
  209. Case dbByte
  210. strType = "BYTE"
  211. Case dbInteger
  212. strType = "SHORT"
  213. Case dbLong
  214. strType = "LONG"
  215. Case dbNumeric
  216. strType = "NUMERIC"
  217. Case dbText
  218. strType = "VARCHAR"
  219. Case dbDecimal
  220. strType = "DECIMAL"
  221. Case Else
  222. strType = "VARCHAR"
  223. End Select
  224. End Function
  225. Private Function FieldsIdentical(ff As Object, gg As Object) As Boolean
  226. Dim f As DAO.Field
  227. If ff.Count <> gg.Count Then
  228. FieldsIdentical = False
  229. Exit Function
  230. End If
  231. For Each f In ff
  232. If Not FieldInFields(f, gg) Then
  233. FieldsIdentical = False
  234. Exit Function
  235. End If
  236. Next
  237. FieldsIdentical = True
  238. End Function
  239. Private Function FieldInFields(fi As DAO.Field, ff As DAO.Fields) As Boolean
  240. Dim f As DAO.Field
  241. For Each f In ff
  242. If f.name = fi.name Then
  243. FieldInFields = True
  244. Exit Function
  245. End If
  246. Next
  247. FieldInFields = False
  248. End Function
  249. ' Determine if a table or exists.
  250. ' based on sample code of support.microsoftcom
  251. ' ARGUMENTS:
  252. ' TName: The name of a table or query.
  253. '
  254. ' RETURNS: True (it exists) or False (it does not exist).
  255. Private Function TableExists(ByVal TName As String) As Boolean
  256. Dim Db As DAO.Database
  257. Dim Found As Boolean
  258. Dim Test As String
  259. Const NAME_NOT_IN_COLLECTION As Integer = 3265
  260. ' Assume the table or query does not exist.
  261. Found = False
  262. Set Db = CurrentDb()
  263. ' Trap for any errors.
  264. On Error Resume Next
  265. ' See if the name is in the Tables collection.
  266. Test = Db.TableDefs(TName).name
  267. If Err.Number <> NAME_NOT_IN_COLLECTION Then Found = True
  268. ' Reset the error variable.
  269. Err = 0
  270. TableExists = Found
  271. End Function
  272. ' Build SQL to export `tbl_name` sorted by each field from first to last
  273. Private Function TableExportSql(ByVal tbl_name As String) As String
  274. Dim rs As Object ' DAO.Recordset
  275. Dim fieldObj As Object ' DAO.Field
  276. Dim sb() As String, Count As Integer
  277. Set rs = CurrentDb.OpenRecordset(tbl_name)
  278. sb = VCS_String.Sb_Init()
  279. VCS_String.Sb_Append sb, "SELECT "
  280. Count = 0
  281. For Each fieldObj In rs.Fields
  282. If Count > 0 Then VCS_String.Sb_Append sb, ", "
  283. VCS_String.Sb_Append sb, "[" & fieldObj.name & "]"
  284. Count = Count + 1
  285. Next
  286. VCS_String.Sb_Append sb, " FROM [" & tbl_name & "] ORDER BY "
  287. Count = 0
  288. For Each fieldObj In rs.Fields
  289. DoEvents
  290. If Count > 0 Then VCS_String.Sb_Append sb, ", "
  291. VCS_String.Sb_Append sb, "[" & fieldObj.name & "]"
  292. Count = Count + 1
  293. Next
  294. TableExportSql = VCS_String.Sb_Get(sb)
  295. End Function
  296. ' Export the lookup table `tblName` to `source\tables`.
  297. Public Sub ExportTableData(ByVal tbl_name As String, ByVal obj_path As String)
  298. Dim FSO As Object
  299. Dim OutFile As Object
  300. Dim rs As DAO.Recordset ' DAO.Recordset
  301. Dim fieldObj As Object ' DAO.Field
  302. Dim c As Long, Value As Variant
  303. ' Checks first
  304. If Not TableExists(tbl_name) Then
  305. Debug.Print "Error: Table " & tbl_name & " missing"
  306. Exit Sub
  307. End If
  308. Set rs = CurrentDb.OpenRecordset(TableExportSql(tbl_name))
  309. If rs.RecordCount = 0 Then
  310. 'why is this an error? Debug.Print "Error: Table " & tbl_name & " empty"
  311. rs.Close
  312. Exit Sub
  313. End If
  314. Set FSO = CreateObject("Scripting.FileSystemObject")
  315. ' open file for writing with Create=True, Unicode=True (USC-2 Little Endian format)
  316. VCS_Dir.MkDirIfNotExist obj_path
  317. Dim tempFileName As String
  318. tempFileName = VCS_File.TempFile()
  319. Set OutFile = FSO.CreateTextFile(tempFileName, overwrite:=True, Unicode:=True)
  320. c = 0
  321. For Each fieldObj In rs.Fields
  322. If c <> 0 Then OutFile.Write vbTab
  323. c = c + 1
  324. OutFile.Write fieldObj.name
  325. Next
  326. OutFile.Write vbCrLf
  327. rs.MoveFirst
  328. Do Until rs.EOF
  329. c = 0
  330. For Each fieldObj In rs.Fields
  331. DoEvents
  332. If c <> 0 Then OutFile.Write vbTab
  333. c = c + 1
  334. Value = rs(fieldObj.name)
  335. If IsNull(Value) Then
  336. Value = vbNullString
  337. Else
  338. Value = Replace(Value, "\", "\\")
  339. Value = Replace(Value, vbCrLf, "\n")
  340. Value = Replace(Value, vbCr, "\n")
  341. Value = Replace(Value, vbLf, "\n")
  342. Value = Replace(Value, vbTab, "\t")
  343. End If
  344. OutFile.Write Value
  345. Next
  346. OutFile.Write vbCrLf
  347. rs.MoveNext
  348. Loop
  349. rs.Close
  350. OutFile.Close
  351. VCS_File.ConvertUcs2Utf8 tempFileName, obj_path & tbl_name & ".txt"
  352. FSO.DeleteFile tempFileName
  353. End Sub
  354. ' Kill Table if Exists
  355. Private Sub KillTable(ByVal tblName As String, Db As Object)
  356. If TableExists(tblName) Then
  357. Db.Execute "DROP TABLE [" & tblName & "]"
  358. End If
  359. End Sub
  360. Public Sub ImportLinkedTable(ByVal tblName As String, ByRef obj_path As String)
  361. Dim Db As DAO.Database
  362. Dim FSO As Object
  363. Dim InFile As Object
  364. Set Db = CurrentDb
  365. Set FSO = CreateObject("Scripting.FileSystemObject")
  366. Dim tempFilePath As String
  367. tempFilePath = VCS_File.TempFile()
  368. ConvertUtf8Ucs2 obj_path & tblName & ".LNKD", tempFilePath
  369. ' open file for reading with Create=False, Unicode=True (USC-2 Little Endian format)
  370. Set InFile = FSO.OpenTextFile(tempFilePath, iomode:=ForReading, create:=False, Format:=TristateTrue)
  371. On Error GoTo err_notable:
  372. DoCmd.DeleteObject acTable, tblName
  373. GoTo err_notable_fin
  374. err_notable:
  375. Err.Clear
  376. Resume err_notable_fin
  377. err_notable_fin:
  378. On Error GoTo Err_CreateLinkedTable:
  379. Dim td As DAO.TableDef
  380. Set td = Db.CreateTableDef(InFile.ReadLine())
  381. Dim connect As String
  382. connect = InFile.ReadLine()
  383. If InStr(1, connect, "DATABASE=.\") Then 'replace relative path with literal path
  384. connect = Replace(connect, "DATABASE=.\", "DATABASE=" & CurrentProject.Path & "\")
  385. End If
  386. td.connect = connect
  387. td.SourceTableName = InFile.ReadLine()
  388. Db.TableDefs.Append td
  389. GoTo Err_CreateLinkedTable_Fin
  390. Err_CreateLinkedTable:
  391. MsgBox Err.Description, vbCritical, "ERROR: IMPORT LINKED TABLE"
  392. Resume Err_CreateLinkedTable_Fin
  393. Err_CreateLinkedTable_Fin:
  394. 'this will throw errors if a primary key already exists or the table is linked to an access database table
  395. 'will also error out if no pk is present
  396. On Error GoTo Err_LinkPK_Fin:
  397. Dim Fields As String
  398. Fields = InFile.ReadLine()
  399. Dim Field As Variant
  400. Dim sql As String
  401. sql = "CREATE INDEX __uniqueindex ON " & td.name & " ("
  402. For Each Field In Split(Fields, ";+")
  403. sql = sql & "[" & Field & "]" & ","
  404. Next
  405. 'remove extraneous comma
  406. sql = Left$(sql, Len(sql) - 1)
  407. sql = sql & ") WITH PRIMARY"
  408. CurrentDb.Execute sql
  409. Err_LinkPK_Fin:
  410. On Error Resume Next
  411. InFile.Close
  412. End Sub
  413. ' Import Table Definition
  414. Public Sub ImportTableDef(ByVal tblName As String, ByVal directory As String)
  415. Dim filePath As String
  416. filePath = directory & tblName & ".sql"
  417. Dim Db As Object ' DAO.Database
  418. Dim FSO As Object
  419. Dim InFile As Object
  420. Dim buf As String
  421. Dim p As Integer
  422. Dim p1 As Integer
  423. Dim strMsg As String
  424. Dim s As Variant
  425. Dim n As Integer
  426. Dim i As Integer
  427. Dim j As Integer
  428. Dim tempFileName As String
  429. tempFileName = VCS_File.TempFile()
  430. n = -1
  431. Set FSO = CreateObject("Scripting.FileSystemObject")
  432. VCS_File.ConvertUtf8Ucs2 filePath, tempFileName
  433. ' open file for reading with Create=False, Unicode=True (USC-2 Little Endian format)
  434. Set InFile = FSO.OpenTextFile(tempFileName, iomode:=ForReading, create:=False, Format:=TristateTrue)
  435. Set Db = CurrentDb
  436. KillTable tblName, Db
  437. buf = InFile.ReadLine()
  438. Do Until InFile.AtEndOfStream
  439. buf = buf & InFile.ReadLine()
  440. Loop
  441. ' The following block is needed because "on update" actions may cause problems
  442. For Each s In Split("UPDATE|DELETE", "|")
  443. p = InStr(buf, "ON " & s & " CASCADE")
  444. Do While p > 0
  445. n = n + 1
  446. ReDim Preserve K(n)
  447. K(n).table = tblName
  448. K(n).isUpdate = (s = "UPDATE")
  449. buf = Left$(buf, p - 1) & Mid$(buf, p + 18)
  450. p = InStrRev(buf, "REFERENCES", p)
  451. p1 = InStr(p, buf, "(")
  452. K(n).foreignFields = Split(VCS_String.SubString(p1, buf, "(", ")"), ",")
  453. K(n).foreignTable = Trim$(Mid$(buf, p + 10, p1 - p - 10))
  454. p = InStrRev(buf, "CONSTRAINT", p1)
  455. p1 = InStrRev(buf, "FOREIGN KEY", p1)
  456. If (p1 > 0) And (p > 0) And (p1 > p) Then
  457. ' multifield index
  458. K(n).refFields = Split(VCS_String.SubString(p1, buf, "(", ")"), ",")
  459. ElseIf p1 = 0 Then
  460. ' single field
  461. End If
  462. p = InStr(p, "ON " & s & " CASCADE", buf)
  463. Loop
  464. Next
  465. On Error Resume Next
  466. For i = 0 To n
  467. strMsg = K(i).table & " to " & K(i).foreignTable
  468. strMsg = strMsg & "( "
  469. For j = 0 To UBound(K(i).refFields)
  470. strMsg = strMsg & K(i).refFields(j) & ", "
  471. Next j
  472. strMsg = Left$(strMsg, Len(strMsg) - 2) & ") to ("
  473. For j = 0 To UBound(K(i).foreignFields)
  474. strMsg = strMsg & K(i).foreignFields(j) & ", "
  475. Next j
  476. strMsg = Left$(strMsg, Len(strMsg) - 2) & ") Check "
  477. If K(i).isUpdate Then
  478. strMsg = strMsg & " on update cascade " & vbCrLf
  479. Else
  480. strMsg = strMsg & " on delete cascade " & vbCrLf
  481. End If
  482. Next
  483. On Error GoTo 0
  484. Db.Execute buf
  485. InFile.Close
  486. If Len(strMsg) > 0 Then MsgBox strMsg, vbOKOnly, "Correct manually"
  487. End Sub
  488. ' Import the lookup table `tblName` from `source\tables`.
  489. Public Sub ImportTableData(ByVal tblName As String, ByVal obj_path As String)
  490. Dim Db As Object ' DAO.Database
  491. Dim rs As Object ' DAO.Recordset
  492. Dim fieldObj As Object ' DAO.Field
  493. Dim FSO As Object
  494. Dim InFile As Object
  495. Dim c As Long, buf As String, Values() As String, Value As Variant
  496. Set FSO = CreateObject("Scripting.FileSystemObject")
  497. Dim tempFileName As String
  498. tempFileName = VCS_File.TempFile()
  499. VCS_File.ConvertUtf8Ucs2 obj_path & tblName & ".txt", tempFileName
  500. ' open file for reading with Create=False, Unicode=True (USC-2 Little Endian format)
  501. Set InFile = FSO.OpenTextFile(tempFileName, iomode:=ForReading, create:=False, Format:=TristateTrue)
  502. Set Db = CurrentDb
  503. Db.Execute "DELETE FROM [" & tblName & "]"
  504. Set rs = Db.OpenRecordset(tblName)
  505. buf = InFile.ReadLine()
  506. Do Until InFile.AtEndOfStream
  507. buf = InFile.ReadLine()
  508. If Len(Trim$(buf)) > 0 Then
  509. Values = Split(buf, vbTab)
  510. c = 0
  511. rs.AddNew
  512. For Each fieldObj In rs.Fields
  513. DoEvents
  514. Value = Values(c)
  515. If Len(Value) = 0 Then
  516. Value = Null
  517. Else
  518. Value = Replace(Value, "\t", vbTab)
  519. Value = Replace(Value, "\n", vbCrLf)
  520. Value = Replace(Value, "\\", "\")
  521. End If
  522. rs(fieldObj.name) = Value
  523. c = c + 1
  524. Next
  525. rs.Update
  526. End If
  527. Loop
  528. rs.Close
  529. InFile.Close
  530. FSO.DeleteFile tempFileName
  531. End Sub