VCS_Loader.bas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. Attribute VB_Name = "VCS_Loader"
  2. Option Compare Database
  3. Option Explicit
  4. Public Sub loadVCS(Optional ByVal SourceDirectory As String)
  5. If SourceDirectory = vbNullString Then
  6. SourceDirectory = CurrentProject.Path & "\MSAccess-VCS\"
  7. End If
  8. 'check if directory exists! - SourceDirectory could be a file or not exist
  9. On Error GoTo Err_DirCheck
  10. If ((GetAttr(SourceDirectory) And vbDirectory) = vbDirectory) Then
  11. GoTo Fin_DirCheck
  12. Else
  13. 'SourceDirectory is not a directory
  14. Err.Raise 60000, "loadVCS", "Source Directory specified is not a directory"
  15. End If
  16. Err_DirCheck:
  17. If Err.Number = 53 Then 'SourceDirectory does not exist
  18. Debug.Print Err.Number & " | " & "File/Directory not found"
  19. Else
  20. Debug.Print Err.Number & " | " & Err.Description
  21. End If
  22. Exit Sub
  23. Fin_DirCheck:
  24. 'delete if modules already exist + provide warning of deletion?
  25. On Error GoTo Err_DelHandler
  26. Dim fileName As String
  27. 'Use the list of files to import as the list to delete
  28. fileName = Dir$(SourceDirectory & "*.bas")
  29. Do Until Len(fileName) = 0
  30. 'strip file type from file name
  31. fileName = Left$(fileName, InStrRev(fileName, ".bas") - 1)
  32. DoCmd.DeleteObject acModule, fileName
  33. fileName = Dir$()
  34. Loop
  35. GoTo Fin_DelHandler
  36. Err_DelHandler:
  37. If Err.Number <> 7874 Then 'is not - can't find object
  38. Debug.Print "WARNING (" & Err.Number & ") | " & Err.Description
  39. End If
  40. Resume Next
  41. Fin_DelHandler:
  42. fileName = vbNullString
  43. 'import files from specific dir? or allow user to input their own dir?
  44. On Error GoTo Err_LoadHandler
  45. fileName = Dir$(SourceDirectory & "*.bas")
  46. Do Until Len(fileName) = 0
  47. 'strip file type from file name
  48. fileName = Left$(fileName, InStrRev(fileName, ".bas") - 1)
  49. Application.LoadFromText acModule, fileName, SourceDirectory & fileName & ".bas"
  50. fileName = Dir$()
  51. Loop
  52. GoTo Fin_LoadHandler
  53. Err_LoadHandler:
  54. Debug.Print Err.Number & " | " & Err.Description
  55. Resume Next
  56. Fin_LoadHandler:
  57. Debug.Print "Done"
  58. End Sub