VCS_Utilities.bas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Option Compare Database
  2. Public Function vcs_tbl_exists()
  3. ' return True if the 'ztbl_vcs' table exists
  4. On Error GoTo err
  5. vcs_tbl_exists = (CurrentDb.TableDefs("ztbl_vcs").name = "ztbl_vcs")
  6. Exit Function
  7. err:
  8. If err.number = 3265 Then
  9. vcs_tbl_exists = False
  10. Else
  11. MsgBox "Error: " & err.Description, vbCritical
  12. End If
  13. End Function
  14. Public Function update_vcs_param(ByVal key As String, ByVal val As String)
  15. ' create or update the parameter in ztbl_vcs
  16. If Not vcs_tbl_exists() Then
  17. Call create_vcs_tbl
  18. End If
  19. If DCount("key", "ztbl_vcs", "[key]='" & key & "'") = 1 Then
  20. CurrentDb.execute "UPDATE ztbl_vcs SET ztbl_vcs.val = '" & val & "' " & _
  21. "WHERE (((ztbl_vcs.key)='" & key & "'));"
  22. Else
  23. CurrentDb.execute "INSERT INTO ztbl_vcs ( val, [key] ) " & _
  24. "SELECT '" & val & "' AS Expr1, '" & key & "' AS Expr2;"
  25. End If
  26. End Function
  27. Public Function create_vcs_tbl()
  28. 'creates the 'ztbl_vcs' table and hide it
  29. CurrentDb.execute "SELECT 'include_tables' as key, 'ztbl_vcs' as val INTO ztbl_vcs;"
  30. Application.SetHiddenAttribute acTable, "ztbl_vcs", True
  31. End Function
  32. Public Function IsInArray(ByVal stringToBeFound As String, ByRef arr As Variant) As Boolean
  33. ' returns True if the string is in the array
  34. IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
  35. End Function
  36. Public Function msys_type_filter(acType) As String
  37. 'returns a sql filter string for the object type
  38. 'NB: do not return system tables
  39. 'NB2: here are the types in msysobjects table:
  40. '-32768 = Form
  41. '-32766 = Macro
  42. '-32764 = Report
  43. '32761 = Module
  44. '-32758 Users
  45. '-32757 Database Document
  46. '-32756 Data Access Pages
  47. '1 Table - Local Access Tables
  48. '2 Access Object - Database
  49. '3 Access Object - Containers
  50. '4 Table - Linked ODBC Tables
  51. '5 Queries
  52. '6 Table - Linked Access Tables
  53. '8 SubDataSheets
  54. Select Case acType
  55. Case acTable
  56. msys_type_filter = "(([Type]=1 or [Type]=4 or [Type]=6) AND ([name] Not Like 'MSys*' AND [name] Not Like 'f_*_Data'))"
  57. Case acQuery
  58. msys_type_filter = "[Type]=5"
  59. Case acForm
  60. msys_type_filter = "[Type]=-32768"
  61. Case acReport
  62. msys_type_filter = "[Type]=-32764"
  63. Case acModule
  64. msys_type_filter = "[Type]=-32761"
  65. Case acMacro
  66. msys_type_filter = "[Type]=-32766"
  67. Case Else
  68. GoTo typerror
  69. End Select
  70. Exit Function
  71. typerror:
  72. MsgBox "typerror:" & acType & " is not a valid object type"
  73. msys_type_filter = ""
  74. End Function
  75. Public Function remove_ext(ByVal filename As String) As String
  76. ' removes the extension of a file name
  77. If Not InStr(filename, ".") > 0 Then
  78. remove_ext = filename
  79. Exit Function
  80. End If
  81. Dim splitted_name As Variant
  82. splitted_name = Split(filename, ".")
  83. Dim i As Integer
  84. remove_ext = ""
  85. For i = 0 To (UBound(Split(filename, ".")) - 1)
  86. If Len(remove_ext) > 0 Then remove_ext = remove_ext & "."
  87. remove_ext = remove_ext & Split(filename, ".")(i)
  88. Next i
  89. End Function