VCS_Loader.bas 2.1 KB

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