| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- Option Compare Database
- Public Function oa_tbl_exists() As Boolean
- ' return True if the 'ztbl_openaccess' table exists
- On Error GoTo err
- oa_tbl_exists = (CurrentDb.TableDefs("ztbl_openaccess").name = "ztbl_openaccess")
- Exit Function
- err:
- If err.number = 3265 Then
- oa_tbl_exists = False
- Else
- MsgBox "Error: " & err.Description, vbCritical
- End If
- End Function
- Public Function update_oa_param(ByVal key As String, ByVal val As String)
- ' create or update the parameter in ztbl_openaccess
- If Not oa_tbl_exists() Then
- Call create_oa_tbl
- End If
- If DCount("key", "ztbl_openaccess", "[key]='" & key & "'") = 1 Then
- CurrentDb.execute "UPDATE ztbl_openaccess SET ztbl_openaccess.val = '" & val & "' " & _
- "WHERE (((ztbl_openaccess.key)='" & key & "'));"
- Else
- CurrentDb.execute "INSERT INTO ztbl_openaccess ( val, [key] ) " & _
- "SELECT '" & val & "' AS Expr1, '" & key & "' AS Expr2;"
- End If
- End Function
- Public Function create_oa_tbl()
- 'creates the 'ztbl_openaccess' table and hide it
- CurrentDb.execute "SELECT 'include_tables' as key, 'ztbl_openaccess' as val INTO ztbl_openaccess;"
- Application.SetHiddenAttribute acTable, "ztbl_openaccess", True
- End Function
- Public Function get_include_tables()
-
- get_include_tables = oa_param("include_tables")
- End Function
- Public Function oa_param(ByVal key As String, Optional ByVal default_value As String = "") As String
- oa_param = default_value
- On Error GoTo err_oa_table
- oa_param = DFirst("val", "ztbl_oa", "[key]='" & key & "'")
- err_oa_table:
- End Function
- Public Function IsInArray(ByVal stringToBeFound As String, ByRef arr As Variant) As Boolean
- ' returns True if the string is in the array
- IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
- End Function
- Public Function msys_type_filter(acType) As String
- 'returns a sql filter string for the object type
- 'NB: do not return system tables
- 'NB2: here are the types in msysobjects table:
- '-32768 = Form
- '-32766 = Macro
- '-32764 = Report
- '32761 = Module
- '-32758 Users
- '-32757 Database Document
- '-32756 Data Access Pages
- '1 Table - Local Access Tables
- '2 Access Object - Database
- '3 Access Object - Containers
- '4 Table - Linked ODBC Tables
- '5 Queries
- '6 Table - Linked Access Tables
- '8 SubDataSheets
- Select Case acType
- Case acTable
- msys_type_filter = "(([Type]=1 or [Type]=4 or [Type]=6) AND ([name] Not Like 'MSys*' AND [name] Not Like 'f_*_Data'))"
- Case acQuery
- msys_type_filter = "[Type]=5"
- Case acForm
- msys_type_filter = "[Type]=-32768"
- Case acReport
- msys_type_filter = "[Type]=-32764"
- Case acModule
- msys_type_filter = "[Type]=-32761"
- Case acMacro
- msys_type_filter = "[Type]=-32766"
- Case Else
- GoTo typerror
- End Select
- Exit Function
- typerror:
- MsgBox "typerror:" & acType & " is not a valid object type"
- msys_type_filter = ""
- End Function
- Public Function remove_ext(ByVal filename As String) As String
- ' removes the extension of a file name
- If Not InStr(filename, ".") > 0 Then
- remove_ext = filename
- Exit Function
- End If
- Dim splitted_name As Variant
- splitted_name = Split(filename, ".")
- Dim i As Integer
- remove_ext = ""
- For i = 0 To (UBound(Split(filename, ".")) - 1)
- If Len(remove_ext) > 0 Then remove_ext = remove_ext & "."
- remove_ext = remove_ext & Split(filename, ".")(i)
- Next i
- End Function
- Public Function complete_gitignore()
- ' creates or complete the .gitignore file of the repo
- Dim gitignore_path, str_existing_keys, str As String
-
- Dim keys() As String
- keys = Split("*.accdb;*.laccdb;*.mdb;*.ldb;*.accde;*.mde;*.accda", ";")
-
- gitignore_path = CurrentProject.path & "\.gitignore"
-
- Dim fso As Object
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- Dim oFile As Object
- If Not fso.FileExists(gitignore_path) Then
- Set oFile = fso.CreateTextFile(gitignore_path)
- Else
- Set oFile = fso.OpenTextFile(gitignore_path, ForReading)
- str_existing_keys = ""
-
- While Not oFile.AtEndOfStream
- str = oFile.readline
- If Len(str_existing_keys) = 0 Then
- str_existing_keys = str
- Else
- str_existing_keys = str_existing_keys & ";" & str
- End If
- Wend
- oFile.Close
-
- Dim existing_keys() As String
- existing_keys = Split(str_existing_keys, ";")
-
- Set oFile = fso.OpenTextFile(gitignore_path, ForAppending)
- End If
-
- oFile.WriteBlankLines (2)
- oFile.WriteLine ("#[ automatically added by OpenAccess")
- For Each key In keys
- If Not IsInArray(key, existing_keys) Then
- oFile.WriteLine key
- End If
- Next key
- oFile.WriteLine "#]"
- oFile.WriteBlankLines (2)
-
- oFile.Close
- Set fso = Nothing
- Set oFile = Nothing
- End Function
|