銀行振込ファイル レコード・フォーマットを参考に、Microsoft Access に取り込むためのモジュールを作った。
以前も作ったことがあるが、すっかり忘れている。Access そのものも忘れているのでてこずった。きれいなコーディングではないだろうが、今後の自分の参考にするためアップした。
1. Option Compare Database 2. Option Explicit 3. Const MYOjbName As String = "M_口座振替処理" 4. Dim BOOLAns As Boolean 5. 6. Public Function link口座振替() As Boolean 7. On Error GoTo Err_link口座振替 8. Dim mbTitle As String 9. Const accTableName As String = "tmp口座振替" 10. Dim FSO As New FileSystemObject 11. Dim TS1 As TextStream, TS2 As TextStream 12. Dim i As Long 13. Dim txt1File As String, txt2File As String, strRec As String 14. Dim defDir As String, defFilter As String 15. Dim FieldName As Variant 16. 17. mbTitle = MYOjbName & "/link口座振替" 18. link口座振替 = False 19. BOOLAns = Delete_aObject(accTableName, "T") 20. '口座振替処理結果ファイル名の取得 21. defFilter = "テキストファイル(*.txt)" + Chr$(0) + ";*.txt" + Chr$(0) + "" _ 22. & "全てのファイル(*.*)" + Chr$(0) + ";*.*" + Chr$(0) + "" 23. txt1File = Get_FileName("口座振替処理結果(TAB区切り) テキストファイルの指定", defDir, defFilter) 24. If txt1File = "" Then Exit Function 25. 26. '1行目のタイトルを取り... 27. Set TS1 = FSO.OpenTextFile(txt1File, ForReading) 28. If TS1.AtEndOfLine Then 29. MsgBox "口座振替処理結果データがありません。", vbCritical, mbTitle 30. TS1.Close: GoTo Exit_link口座振替 31. End If 32. strRec = TS1.ReadLine 33. If strRec <> "口座振替処理結果" Then 34. MsgBox "口座振替処理結果データではありません。" _ 35. & " ■Title=" & strRec _ 36. , vbCritical, mbTitle 37. TS1.Close: GoTo Exit_link口座振替 38. End If 39. '出力ファイルを開く 40. txt2File = get_myMDBPath() & strRec & ".tmp" 41. Set TS2 = FSO.CreateTextFile(txt2File, True) 42. '2行目の"データ区分"をユニークにして 43. If Not TS1.AtEndOfLine Then 44. strRec = TS1.ReadLine 45. FieldName = Split(strRec, vbTab, -1, vbTextCompare) 46. For i = 0 To UBound(FieldName) 47. If FieldName(i) = "データ区分" Then FieldName(i) = FieldName(i) & i 48. Next 49. End If 50. '書き出す。 51. TS2.WriteLine Join(FieldName, vbTab) 52. '残りはそのまま書き出す。 53. Do Until TS1.AtEndOfStream 54. strRec = TS1.ReadLine 55. TS2.WriteLine strRec 56. Loop 57. TS1.Close: TS2.Close 58. 'リンクする。 59. DoCmd.TransferText acLinkDelim, "口座振替処理結果 リンク定義", accTableName, txt2File, True 60. link口座振替 = True 61. 62. Exit_link口座振替: 63. Set TS1 = Nothing: Set TS2 = Nothing 64. Exit Function 65. 66. Err_link口座振替: 67. MsgBox Err.Number & "/" & Err.Description 68. Resume Exit_link口座振替 69. End Function
- 連番を振るため、次の方法で記事を入力した。
- Word に貼り付け、pdf で出力する手があるかも...
- モジュールを Word にコピペする。
- コードが1行に収まるよう余白を調整する。
- 連番を振る。([ページ設定]⇒[その他]タブ ⇒[行番号]ボタン)
- [瞬間PDF Zero]で印刷
- 作るのは簡単だが、
- インタネットで「コード」を検索することはできない。