-
Notifications
You must be signed in to change notification settings - Fork 3
/
M_omDatabaseFunctions.def
60 lines (51 loc) · 2.05 KB
/
M_omDatabaseFunctions.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Option Compare Database
Option Explicit
Public Sub LinkTable(databaseFilename As String, sourceName As String, destinationName As String)
UnlinkTable destinationName
DoCmd.TransferDatabase acLink, "Microsoft Access", databaseFilename, acTable, sourceName, destinationName
End Sub
Public Sub UnlinkTable(Name As String)
On Error Resume Next
DoCmd.DeleteObject acTable, Name
On Error GoTo 0
End Sub
Public Function CreateDataBase(fileName As String) As Boolean
Dim varReturn As Variant
On Error GoTo CreateDB_Error
CreateDataBase = True
DBEngine.CreateDataBase fileName, dbLangGeneral
Exit Function
CreateDB_Error:
Select Case Err
Case Else
CreateDataBase = False
End Select
End Function
Public Function ExportTable(fileName As String, sourceName As String, destinationName As String) As Boolean
On Error GoTo ExportTable_Error
ExportTable = True
DoCmd.TransferDatabase acExport, "Microsoft Access", fileName, acTable, sourceName, destinationName, False
Exit Function
ExportTable_Error:
ExportTable = False
End Function
Public Function CompactDataBase(fileName As String)
Dim dstFilename As String
On Error GoTo CompactDataBase_Error
CompactDataBase = True
dstFilename = fileName & "_" & (((Year(Date) * 100 + Month(Date)) * 100 + Day(Date)) * 100 + Hour(Time)) * 100 + Minute(Time)
DBEngine.CompactDataBase fileName, dstFilename
DeleteFile fileName
RenameFile dstFilename, fileName
Exit Function
CompactDataBase_Error:
CompactDataBase = False
End Function
Public Function CopyTable(databaseFilename As String, TableSource As String, TableDestination As String) As Variant
On Error Resume Next
DoCmd.DeleteObject acTable, "_" & TableSource
On Error GoTo 0
DoCmd.TransferDatabase acImport, "Microsoft Access", databaseFilename, acTable, TableSource, "_" & TableSource
DoCmd.TransferDatabase acExport, "Microsoft Access", databaseFilename, acTable, "_" & TableSource, TableDestination
DoCmd.DeleteObject acTable, "_" & TableSource
End Function