-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathM_omExportManager.def
205 lines (199 loc) · 7.72 KB
/
M_omExportManager.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Compare Database
Option Explicit
Const emExcel = 1
Const emWord = 2
Const emPDF = 3
Private bMyDocuments As Boolean
Private strExportPath As String
Private strTemplatePath As String
Private strExportName As String
Private strTemplateFilename As String
Private strTemplate As String
Private bAppendDate As Boolean
Private bAppendName As Boolean
Private iExportType As Integer
Private lPhysicalDocumentTypeId As Long
Private lSupplierId As Long
Private lContractId As Long
Private lContractPeriodId As Long
Private strDBDocument As String
Private FSO As New FileSystemObject
Private WShell As New WshShell
Private bAutoOpen As Boolean
Private strFileDestination As String
Public Property Get destinationFilename() As String
destinationFilename = strFileDestination
End Property
Public Property Get MyDocuments() As Boolean
MyDocuments = bMyDocuments
End Property
Public Property Let MyDocuments(Value As Boolean)
bMyDocuments = Value
strTemplatePath = GetDefaultValue("Templates")
If bMyDocuments Then
strExportPath = FSO.BuildPath(WShell.SpecialFolders("MyDocuments"), "DBExports")
If Not FSO.FolderExists(strExportPath) Then
FSO.createFolder strExportPath
End If
Else
strExportPath = GetDefaultValue("ExportPath")
End If
End Property
Public Property Get AppendDate() As Boolean
AppendDate = bAppendDate
End Property
Public Property Let AppendDate(Value As Boolean)
bAppendDate = Value
End Property
Public Property Get AppendName() As Boolean
AppendName = bAppendName
End Property
Public Property Let AppendName(Value As Boolean)
bAppendName = Value
End Property
Public Property Get ExportName() As String
ExportName = strExportName
End Property
Public Property Let ExportName(Value As String)
strExportName = Value
End Property
Public Property Get AutoOpen() As Boolean
AutoOpen = bAutoOpen
End Property
Public Property Let AutoOpen(Value As Boolean)
bAutoOpen = Value
End Property
Public Property Get Template() As String
Template = strTemplate
End Property
Public Property Let Template(Value As String)
strTemplate = Value
End Property
Public Property Get TemplatePath() As String
TemplatePath = strTemplatePath
End Property
Public Property Let TemplatePath(Value As String)
strTemplatePath = Value
End Property
Public Property Get ExportPath() As String
ExportPath = strExportPath
End Property
Public Property Let ExportPath(Value As String)
strExportPath = Value
End Property
Public Property Get ExportType() As Integer
ExportType = iExportType
End Property
Public Property Let ExportType(Value As Integer)
iExportType = Value
End Property
Public Property Get PhysicalDocumentTypeId() As Long
PhysicalDocumentTypeId = lPhysicalDocumentTypeId
End Property
Public Property Let PhysicalDocumentTypeId(Value As Long)
lPhysicalDocumentTypeId = Value
End Property
Public Property Get SupplierId() As Long
SupplierId = lSupplierId
End Property
Public Property Let SupplierId(Value As Long)
lSupplierId = Value
End Property
Public Property Get ContractId() As Long
ContractId = lContractId
End Property
Public Property Let ContractId(Value As Long)
lContractId = Value
End Property
Public Property Get ContractPeriodId() As Long
ContractPeriodId = lContractPeriodId
End Property
Public Property Let ContractPeriodId(Value As Long)
lContractPeriodId = Value
End Property
Public Property Get dbDocument() As String
dbDocument = strDBDocument
End Property
Public Property Let dbDocument(Value As String)
strDBDocument = Value
End Property
Public Sub Export()
Dim strFileSource As String
Dim strSupplierName As String
Dim rs As New ADODB.Recordset
If bAppendName Then
rs.Open "SELECT DISTINCT Supplier_LastName, Supplier_FirstName FROM (Suppliers LEFT JOIN Contracts ON Suppliers.Supplier_ID = Contracts.Contract_Supplier_ID) LEFT JOIN ContractPeriods ON Contracts.Contract_ID = ContractPeriods.ContractPeriod_Contract_ID WHERE Supplier_ID=" & lSupplierId & " OR Contract_ID=" & lContractId & " OR ContractPeriod_ID=" & lContractPeriodId, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
If Not rs.EOF Then
strSupplierName = MakeFilenameSafe(rs("Supplier_LastName") & "_" & rs("Supplier_FirstName"))
strExportName = strExportName & "_" & strSupplierName
End If
rs.Close
Set rs = Nothing
End If
If bAppendDate Then
strExportName = strExportName & Format(Now, "_YYYYMMDD_hhmm")
End If
Select Case iExportType
Case emExcel
If Not gFSO.FolderExists("c:\DBExports") Then
gFSO.createFolder "c:\dbexports"
End If
strFileSource = FSO.BuildPath("c:\dbexports", strExportName & ".xls")
If lPhysicalDocumentTypeId <> 0 And lSupplierId <> 0 Then
strExportPath = gSupplierPhysicalDocument.GetPhysicalDocumentFolderByType(lSupplierId, lPhysicalDocumentTypeId)
End If
strFileDestination = FSO.BuildPath(strExportPath, strExportName & ".xls")
If FSO.FileExists(strFileSource) Then
FSO.DeleteFile strFileSource
End If
If FSO.FileExists(strFileDestination) Then
FSO.DeleteFile strFileDestination
End If
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strDBDocument, strFileSource
Case emWord
If Len(Template) > 0 Then
If lPhysicalDocumentTypeId <> 0 And lSupplierId <> 0 Then
strExportPath = gSupplierPhysicalDocument.GetPhysicalDocumentFolderByType(lSupplierId, lPhysicalDocumentTypeId)
End If
strFileDestination = FSO.BuildPath(strExportPath, strExportName & ".doc")
If gFSO.FileExists(gFSO.BuildPath(strTemplatePath, strTemplate)) Then
gWordEngine.Translate gFSO.BuildPath(strTemplatePath, strTemplate), strFileDestination, strDBDocument
End If
Else
strFileSource = FSO.BuildPath("C:\", strExportName & ".doc")
strFileDestination = FSO.BuildPath(strExportPath, strExportName & ".doc")
If FSO.FileExists(strFileSource) Then
FSO.DeleteFile strFileSource
End If
If FSO.FileExists(strFileDestination) Then
FSO.DeleteFile strFileDestination
End If
If ReportExists(strDBDocument) Then
DoCmd.OutputTo acOutputReport, strDBDocument, acFormatRTF, strFileSource
ElseIf QueryExists(strDBDocument) Then
DoCmd.OutputTo acOutputQuery, strDBDocument, acFormatRTF, strFileSource
End If
End If
Case emPDF
If Len(Template) > 0 Then
If lPhysicalDocumentTypeId <> 0 And lSupplierId <> 0 Then
strExportPath = gSupplierPhysicalDocument.GetPhysicalDocumentFolderByType(lSupplierId, lPhysicalDocumentTypeId)
End If
strFileDestination = FSO.BuildPath(strExportPath, strExportName & ".pdf")
strTemplateFilename = gFSO.BuildPath(strTemplatePath, strTemplate)
If gFSO.FileExists(strTemplateFilename) Then
PDFForm.PDFFormFilling strTemplateFilename, strFileDestination, strDBDocument, "", "", "", "", "_", "."
End If
End If
End Select
If FSO.FileExists(strFileSource) Then
FSO.moveFile strFileSource, strFileDestination
End If
If bAutoOpen Then
WShell.Run Chr(34) & strFileDestination & Chr(34)
End If
End Sub