-
Notifications
You must be signed in to change notification settings - Fork 3
/
M_omDevelopmentFunctions.def
299 lines (276 loc) · 13.2 KB
/
M_omDevelopmentFunctions.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
Option Compare Database
Option Explicit
Public Sub ExportQueries()
Dim rsQueries As New ADODB.Recordset
Dim fno As Long
fno = FreeFile
Open "Queries.txt" For Output As fno
rsQueries.Open "SELECT Name FROM MSysObjects WHERE Type = 5", CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
While Not rsQueries.EOF
Print #fno, "Create Procedure " & Chr(34) & rsQueries("Name") & Chr(34) & vbCrLf
Print #fno, "As" & vbCrLf
Print #fno, DBEngine(0)(0).QueryDefs(rsQueries("Name")).sql & vbCrLf
rsQueries.MoveNext
Wend
rsQueries.Close
Set rsQueries = Nothing
Close fno
End Sub
Public Sub TemplateCopy(strFind As String, strReplace As String)
QueryCopy strFind & "_List_Search", strFind, strReplace
QueryCopy strFind & "_Select", strFind, strReplace
DBEngine(0)(0).QueryDefs.Refresh
FormCopy strFind & "_Edit", strFind, strReplace
FormCopy strFind & "_List", strFind, strReplace
FormCopy strFind & "_List_Search", strFind, strReplace
End Sub
Public Sub QueryCopy(strQuery As String, strFind As String, strReplace As String)
Dim strNewQuery As String
Dim strsql As String
strNewQuery = Replace(strQuery, GetEnglishPlural(strFind), GetEnglishPlural(strReplace))
strNewQuery = Replace(strNewQuery, strFind, strReplace)
DoCmd.CopyObject , strNewQuery, acQuery, strQuery
DBEngine(0)(0).QueryDefs.Refresh
strsql = DBEngine(0)(0).QueryDefs(strNewQuery).sql
strsql = Replace(strsql, GetEnglishPlural(strFind), GetEnglishPlural(strReplace))
strsql = Replace(strsql, strFind, strReplace)
DBEngine(0)(0).QueryDefs(strNewQuery).sql = strsql
DBEngine(0)(0).QueryDefs.Refresh
End Sub
Public Sub FormCopy(strForm As String, strFind As String, strReplace As String)
Dim strNewForm As String
strNewForm = Replace(strForm, strFind, strReplace)
DoCmd.CopyObject , strNewForm, acForm, strForm
FormControlRename strNewForm, 0, GetEnglishPlural(strFind), GetEnglishPlural(strReplace)
FormControlRename strNewForm, 0, strFind, strReplace
End Sub
Public Sub FormControlRename(strForm As String, lControlType As Long, strFind As String, strReplace As String, Optional OnlyCaption As Boolean = False, Optional TestRun As Boolean = False)
Dim bChanged As Boolean
Dim frmEdit As Form
Dim lStartLine As Long
Dim lStartCol As Long
Dim lEndLine As Long
Dim lEndCol As Long
Dim strFound As String
Dim lCount As Long
Dim ctl As Control
Dim i As Long
FormControlRename_Restart:
DoCmd.OpenForm strForm, acDesign, , , , acHidden
bChanged = False
For i = 0 To Forms(strForm).Controls.Count - 1
Set ctl = Forms(strForm).Controls(i)
With ctl
If .ControlType = lControlType Or lControlType = 0 Then
Select Case .ControlType
Case acTextBox, acComboBox
If (InStr(1, .Name, strFind) > 0 Or InStr(1, .ControlSource, strFind) > 0) And InStr(1, .Name, strReplace) > 0 And InStr(1, .ControlSource, strReplace) > 0 Then
If TestRun Then
Debug.Print strForm, .Name, .ControlSource
Else
bChanged = True
.Name = Replace(.Name, strFind, strReplace)
.ControlSource = Replace(.ControlSource, strFind, strReplace)
End If
End If
Case acLabel, acCommandButton
If (InStr(1, .Name, strFind) > 0 Or InStr(1, .Caption, strFind) > 0) And InStr(1, .Caption, strReplace) = 0 And InStr(1, .Name, strReplace) = 0 Then
If TestRun Then
Debug.Print strForm, .Name, .Caption
Else
bChanged = True
If Not OnlyCaption Then
.Name = Replace(.Name, strFind, strReplace)
End If
.Caption = Replace(.Caption, strFind, strReplace)
End If
End If
Case acSubform
If (InStr(1, .Name, strFind) > 0 Or InStr(1, .SourceObject, strFind) > 0) And InStr(1, .Name, strReplace) = 0 And InStr(1, .SourceObject, strReplace) = 0 Then
If TestRun Then
Debug.Print strForm, .Name, .SourceObject
Else
bChanged = True
.Name = Replace(.Name, strFind, strReplace)
.SourceObject = Replace(.SourceObject, strFind, strReplace)
End If
End If
End Select
End If
End With
'If bChanged Then
' Exit For
'End If
Next
If bChanged Then
DoCmd.Close acForm, strForm, acSaveYes
GoTo FormControlRename_Restart
End If
If lControlType = 0 Then
With Forms(strForm)
.RecordSource = Replace(.RecordSource, strFind, strReplace)
.Caption = Replace(.Caption, strFind, strReplace)
End With
Set frmEdit = Forms(strForm)
While frmEdit.Module.Find(strFind, lStartLine, lStartCol, lEndLine, lEndCol)
strFound = frmEdit.Module.Lines(lStartLine, 1)
strFound = Replace(strFound, strFind, strReplace)
frmEdit.Module.ReplaceLine lStartLine, strFound
lStartLine = lEndLine + 1
lStartCol = 0
lEndLine = 0
lEndCol = 0
Wend
End If
DoCmd.Close acForm, strForm, acSaveYes
End Sub
Public Sub DeleteTempObjects()
Dim rs As New ADODB.Recordset
rs.Open "SELECT Name, Type FROM MSysObjects WHERE Name Like '~%'", CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
While Not rs.EOF
Debug.Print rs(0), rs(1)
Select Case rs(1)
Case 5
DoCmd.DeleteObject acQuery, rs(0)
Case -32764
DoCmd.DeleteObject acReport, rs(0)
End Select
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
End Sub
Public Sub ReportReplaceBackColor(reportName As String, OldColor As Long, NewColor As Long)
Dim ctrl As Control
Dim InvalidProperty As Boolean
' ReportReplaceBackColor "SCreditnote",1384554,472939
' ReportReplaceBackColor "SCreditnote_HulchiBelluni2002",1384554,472939
' ReportReplaceBackColor "SCreditnote_ProductCosts",1384554,472939
' ReportReplaceBackColor "SCreditnote_Sub",1384554,472939
' ReportReplaceBackColor "SCreditnote_Sub_HulchiBelluni2002",1384554,472939
' ReportReplaceBackColor "SInvoice",1384554,472939
' ReportReplaceBackColor "SInvoice_HulchiBelluni2002",1384554,472939
' ReportReplaceBackColor "SInvoice_ProductCosts",1384554,472939
' ReportReplaceBackColor "SInvoice_Sub",1384554,472939
' ReportReplaceBackColor "SInvoice_Sub_HulchiBelluni2002",1384554,472939
' ReportReplaceBackColor "SOrder_Outstanding",1384554,472939
' ReportReplaceBackColor "SOrder_Print",1384554,472939
' ReportReplaceBackColor "SOrder_Print_Ordered",1384554,472939
' ReportReplaceBackColor "SOrderDetail_Print",1384554,472939
' ReportReplaceBackColor "SOrderDetail_Print_Ordered",1384554,472939
' ReportReplaceBackColor "SOrderProduct_Print",1384554,472939
' ReportReplaceBackColor "SOrderProductCost_Print",1384554,472939
' ReportReplaceBackColor "SPricelistProduct_Print",1384554,472939
' ReportReplaceBackColor "SPricelistProductFull_Print",1384554,472939
' ReportReplaceBackColor "SPricelistProductFullProductCost_Print",1384554,472939
' ReportReplaceBackColor "SPriceListProductPrice_Print",1384554,472939
' ReportReplaceBackColor "SPriceListProductPrice2_Print",1384554,472939
' ReportReplaceBackColor "SPricelistProductProductCost_Print",1384554,472939
On Error GoTo ReportReplaceBackColor_Error
DoCmd.OpenReport reportName, acViewDesign
For Each ctrl In Reports(reportName).Controls
InvalidProperty = False
If ctrl.BackColor = OldColor Then
If Not InvalidProperty Then
ctrl.BackColor = NewColor
End If
End If
Next
DoCmd.Close acReport, reportName, acSaveYes
Exit Sub
ReportReplaceBackColor_Error:
InvalidProperty = True
Resume Next
End Sub
Public Sub ReportReplaceForeColor(reportName As String, OldColor As Long, NewColor As Long)
Dim ctrl As Control
Dim InvalidProperty As Boolean
' ReportReplaceForeColor "SOrder_Print",1384554,472939
On Error GoTo ReportReplaceForeColor_Error
DoCmd.OpenReport reportName, acViewDesign
For Each ctrl In Reports(reportName).Controls
InvalidProperty = False
If ctrl.ForeColor = OldColor Then
If Not InvalidProperty Then
ctrl.ForeColor = NewColor
End If
End If
Next
DoCmd.Close acReport, reportName, acSaveYes
Exit Sub
ReportReplaceForeColor_Error:
InvalidProperty = True
Resume Next
End Sub
Public Sub ReportReplaceColors()
ReportReplaceBackColor "SCreditnote", 1384554, 472939
ReportReplaceBackColor "SCreditnote_HulchiBelluni2002", 1384554, 472939
ReportReplaceBackColor "SCreditnote_ProductCosts", 1384554, 472939
ReportReplaceBackColor "SCreditnote_Sub", 1384554, 472939
ReportReplaceBackColor "SCreditnote_Sub_HulchiBelluni2002", 1384554, 472939
ReportReplaceBackColor "SInvoice", 1384554, 472939
ReportReplaceBackColor "SInvoice_HulchiBelluni2002", 1384554, 472939
ReportReplaceBackColor "SInvoice_ProductCosts", 1384554, 472939
ReportReplaceBackColor "SInvoice_Sub", 1384554, 472939
ReportReplaceBackColor "SInvoice_Sub_HulchiBelluni2002", 1384554, 472939
ReportReplaceBackColor "SOrder_Outstanding", 1384554, 472939
ReportReplaceBackColor "SOrder_Print", 1384554, 472939
ReportReplaceBackColor "SOrder_Print_Ordered", 1384554, 472939
ReportReplaceBackColor "SOrderDetail_Print", 1384554, 472939
ReportReplaceBackColor "SOrderDetail_Print_Ordered", 1384554, 472939
ReportReplaceBackColor "SOrderProduct_Print", 1384554, 472939
ReportReplaceBackColor "SOrderProductCost_Print", 1384554, 472939
ReportReplaceBackColor "SPricelistProduct_Print", 1384554, 472939
ReportReplaceBackColor "SPricelistProductFull_Print", 1384554, 472939
ReportReplaceBackColor "SPricelistProductFullProductCost_Print", 1384554, 472939
ReportReplaceBackColor "SPriceListProductPrice_Print", 1384554, 472939
ReportReplaceBackColor "SPriceListProductPrice2_Print", 1384554, 472939
ReportReplaceBackColor "SPricelistProductProductCost_Print", 1384554, 472939
ReportReplaceForeColor "SCreditnote", 1384554, 472939
ReportReplaceForeColor "SCreditnote_HulchiBelluni2002", 1384554, 472939
ReportReplaceForeColor "SCreditnote_ProductCosts", 1384554, 472939
ReportReplaceForeColor "SCreditnote_Sub", 1384554, 472939
ReportReplaceForeColor "SCreditnote_Sub_HulchiBelluni2002", 1384554, 472939
ReportReplaceForeColor "SInvoice", 1384554, 472939
ReportReplaceForeColor "SInvoice_HulchiBelluni2002", 1384554, 472939
ReportReplaceForeColor "SInvoice_ProductCosts", 1384554, 472939
ReportReplaceForeColor "SInvoice_Sub", 1384554, 472939
ReportReplaceForeColor "SInvoice_Sub_HulchiBelluni2002", 1384554, 472939
ReportReplaceForeColor "SOrder_Outstanding", 1384554, 472939
ReportReplaceForeColor "SOrder_Print", 1384554, 472939
ReportReplaceForeColor "SOrder_Print_Ordered", 1384554, 472939
ReportReplaceForeColor "SOrderDetail_Print", 1384554, 472939
ReportReplaceForeColor "SOrderDetail_Print_Ordered", 1384554, 472939
ReportReplaceForeColor "SOrderProduct_Print", 1384554, 472939
ReportReplaceForeColor "SOrderProductCost_Print", 1384554, 472939
ReportReplaceForeColor "SPricelistProduct_Print", 1384554, 472939
ReportReplaceForeColor "SPricelistProductFull_Print", 1384554, 472939
ReportReplaceForeColor "SPricelistProductFullProductCost_Print", 1384554, 472939
ReportReplaceForeColor "SPriceListProductPrice_Print", 1384554, 472939
ReportReplaceForeColor "SPriceListProductPrice2_Print", 1384554, 472939
ReportReplaceForeColor "SPricelistProductProductCost_Print", 1384554, 472939
End Sub
Public Sub AllFormsReplace(strFind As String, strReplace As String)
Dim i As Long
For i = 0 To CurrentProject.AllForms.Count - 1
'Debug.Print CurrentProject.AllForms(i).Name
omDevelopmentFunctions.FormControlRename CurrentProject.AllForms(i).Name, acLabel, strFind, strReplace, True, False
omDevelopmentFunctions.FormControlRename CurrentProject.AllForms(i).Name, acCommandButton, strFind, strReplace, True, False
Next
End Sub
Public Sub AllFormsDisableDialog()
Dim i As Long
For i = 0 To CurrentProject.AllForms.Count - 1
DoCmd.OpenForm CurrentProject.AllForms(i).Name, acDesign, windowMode:=acHidden
Forms(CurrentProject.AllForms(i).Name).Modal = False
DoCmd.Close acForm, CurrentProject.AllForms(i).Name, acSaveYes
Next
End Sub
Public Sub AllFormsDisablePopUp()
Dim i As Long
For i = 0 To CurrentProject.AllForms.Count - 1
DoCmd.OpenForm CurrentProject.AllForms(i).Name, acDesign, windowMode:=acHidden
Forms(CurrentProject.AllForms(i).Name).PopUp = False
DoCmd.Close acForm, CurrentProject.AllForms(i).Name, acSaveYes
Next
End Sub