optimizer.bas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. Option Compare Database
  2. Option Explicit
  3. Public Function get_last_update_date(ByVal acType As Integer, ByVal name As String)
  4. On Error GoTo err
  5. Select Case acType
  6. Case acTable
  7. get_last_update_date = DFirst("DateUpdate", "MSysObjects", "([Type]=1 or [Type]=4 or [Type]=6) and [name]='" & name & "'")
  8. Case acQuery
  9. get_last_update_date = DFirst("DateUpdate", "MSysObjects", "[Type]=5 and [name]='" & name & "'")
  10. Case acForm
  11. get_last_update_date = CurrentProject.AllForms(name).DateModified
  12. Case acReport
  13. get_last_update_date = CurrentProject.AllReports(name).DateModified
  14. Case acMacro
  15. get_last_update_date = CurrentProject.AllMacros(name).DateModified
  16. Case acModule
  17. get_last_update_date = CurrentProject.AllModules(name).DateModified
  18. End Select
  19. Exit Function
  20. err:
  21. Debug.Print "get_last_update_date - erreur - " & acType & ", " & name & ": " & err.Description
  22. get_last_update_date = #1/1/1900#
  23. End Function
  24. Public Function list_modified(acType As Integer)
  25. Dim sources_date As Date
  26. list_modified = ""
  27. sources_date = get_sources_date()
  28. Dim rs As DAO.Recordset
  29. Set rs = CurrentDb.OpenRecordset("SELECT * FROM MSysObjects WHERE " & typefilter(acType) & ";", _
  30. dbOpenSnapshot)
  31. If rs.RecordCount = 0 Then GoTo emptylist
  32. rs.MoveFirst
  33. Do Until rs.EOF
  34. If rs![dateupdate] > sources_date Then
  35. If Len(list_modified) > 0 Then
  36. list_modified = list_modified & ";" & rs![name]
  37. Else
  38. list_modified = rs![name]
  39. End If
  40. End If
  41. rs.MoveNext
  42. Loop
  43. Exit Function
  44. emptylist:
  45. End Function
  46. Public Function msg_list_modified() As String
  47. Dim lstmod, obj_type_split, obj_type_label, obj_type_num As String
  48. Dim obj_type, objname As Variant
  49. msg_list_modified = ""
  50. For Each obj_type In Split( _
  51. "tables|" & acTable & "," & _
  52. "queries|" & acQuery & "," & _
  53. "forms|" & acForm & "," & _
  54. "reports|" & acReport & "," & _
  55. "macros|" & acMacro & "," & _
  56. "modules|" & acModule _
  57. , "," _
  58. )
  59. obj_type_split = Split(obj_type, "|")
  60. obj_type_label = obj_type_split(0)
  61. obj_type_num = obj_type_split(1)
  62. lstmod = list_modified(CInt(obj_type_num))
  63. If Len(lstmod) > 0 Then
  64. msg_list_modified = msg_list_modified & "** " & UCase(obj_type_label) & " **" & vbNewLine
  65. For Each objname In Split(lstmod, ";")
  66. msg_list_modified = msg_list_modified & " " & objname & vbNewLine
  67. Next objname
  68. End If
  69. Next obj_type
  70. End Function
  71. Public Function is_dirty(acType As Integer, name As String)
  72. is_dirty = (get_last_update_date(acType, name) > get_sources_date)
  73. End Function
  74. Public Function get_sources_date() As Date
  75. get_sources_date = CDate(vcs_param("sources_date", "01/01/1900 00:00:00"))
  76. End Function
  77. Public Sub update_sources_date()
  78. If Not vcs_tbl_exists() Then
  79. Call create_vcs_tbl
  80. End If
  81. Call update_vcs_param("sources_date", CStr(Now))
  82. End Sub
  83. 'NB: types msys
  84. '-32768 = Form
  85. '-32766 = Macro
  86. '-32764 = Report
  87. '-32761 = Module
  88. '-32758 Users
  89. '-32757 Database Document
  90. '-32756 Data Access Pages
  91. '1 Table - Local Access Tables
  92. '2 Access Object - Database
  93. '3 Access Object - Containers
  94. '4 Table - Linked ODBC Tables
  95. '5 Queries
  96. '6 Table - Linked Access Tables
  97. '8 SubDataSheets
  98. Private Function typefilter(acType) As String
  99. Select Case acType
  100. Case acTable
  101. typefilter = "([Type]=1 or [Type]=4 or [Type]=6)"
  102. Case acQuery
  103. typefilter = "[Type]=5"
  104. Case acForm
  105. typefilter = "[Type]=-32768"
  106. Case acReport
  107. typefilter = "[Type]=-32764"
  108. Case acModule
  109. typefilter = "[Type]=-32761"
  110. Case acMacro
  111. typefilter = "[Type]=-32766"
  112. Case Else
  113. GoTo typerror
  114. End Select
  115. Exit Function
  116. typerror:
  117. MsgBox "typerror:" & acType & " is not a valid object type"
  118. typefilter = ""
  119. End Function