VCS_Utilities.bas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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: types in msysobjects table
  39. '-32768 = Form
  40. '-32766 = Macro
  41. '-32764 = Report
  42. '32761 = Module
  43. '-32758 Users
  44. '-32757 Database Document
  45. '-32756 Data Access Pages
  46. '1 Table - Local Access Tables
  47. '2 Access Object - Database
  48. '3 Access Object - Containers
  49. '4 Table - Linked ODBC Tables
  50. '5 Queries
  51. '6 Table - Linked Access Tables
  52. '8 SubDataSheets
  53. Select Case acType
  54. Case acTable
  55. msys_type_filter = "([Type]=1 or [Type]=4 or [Type]=6)"
  56. Case acQuery
  57. msys_type_filter = "[Type]=5"
  58. Case acForm
  59. msys_type_filter = "[Type]=-32768"
  60. Case acReport
  61. msys_type_filter = "[Type]=-32764"
  62. Case acModule
  63. msys_type_filter = "[Type]=-32761"
  64. Case acMacro
  65. msys_type_filter = "[Type]=-32766"
  66. Case Else
  67. GoTo typerror
  68. End Select
  69. Exit Function
  70. typerror:
  71. MsgBox "typerror:" & acType & " is not a valid object type"
  72. msys_type_filter = ""
  73. End Function
  74. Public Function remove_ext(ByVal filename As String) As String
  75. ' removes the extension of a file name
  76. If Not InStr(filename, ".") > 0 Then
  77. remove_ext = filename
  78. Exit Function
  79. End If
  80. Dim splitted_name As Variant
  81. splitted_name = Split(filename, ".")
  82. Dim i As Integer
  83. remove_ext = ""
  84. For i = 0 To (UBound(Split(filename, ".")) - 1)
  85. If Len(remove_ext) > 0 Then remove_ext = remove_ext & "."
  86. remove_ext = remove_ext & Split(filename, ".")(i)
  87. Next i
  88. End Function