-
Notifications
You must be signed in to change notification settings - Fork 3
/
M_omLibraryFunctions.def
657 lines (596 loc) · 25.2 KB
/
M_omLibraryFunctions.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
Option Compare Database
Option Explicit
Private Function InternalGetTimeStamp(Optional prefix As String = "_") As String
InternalGetTimeStamp = prefix & Format(Now, "yyyymmdd_hhnnss")
End Function
Public Function ExportLibrary(Optional createFolder As Boolean = False, Optional startsWith As String = "om", Optional filenameWithTimestamp As Boolean = False) As String
Dim c As VBComponent
Dim sfx As String
Dim ts As String
Dim fn As String
Dim path As String
ts = InternalGetTimeStamp("")
path = CurrentProject.path
If createFolder Then
path = gFso.BuildPath(path, ts)
If Not gFso.FolderExists(path) Then
gFso.createFolder path
End If
End If
ExportLibrary = path
For Each c In Application.VBE.VBProjects(1).VBComponents
Select Case c.Type
Case vbext_ct_ClassModule, vbext_ct_Document
sfx = ".cls"
Case vbext_ct_MSForm
sfx = ".frm"
Case vbext_ct_StdModule
sfx = ".bas"
Case Else
sfx = ""
End Select
If sfx <> "" And StrComp(Left(c.Name, Len(startsWith)), startsWith, vbBinaryCompare) = 0 Then
fn = path & "\" & c.Name & IIf(filenameWithTimestamp, "_" & ts, "") & sfx
c.Export filename:=fn
End If
Next c
End Function
Public Sub UpdateLibrary(Optional backupComponents As Boolean = True, Optional useUpdatesFolder As Boolean = True, Optional deleteAfterUpdate As Boolean = True)
Dim c As VBComponent
Dim cNew As VBComponent
Dim sfx As String
Dim fn As String
Dim path As String
Dim oName As String
Dim OType As AcObjectType
ExportLibrary True
path = CurrentProject.path
If useUpdatesFolder Then
path = gFso.BuildPath(path, "Updates")
If Not gFso.FolderExists(path) Then
msgbox "Updates Folder does not exist: " & path
Exit Sub
End If
End If
For Each c In Application.VBE.VBProjects(1).VBComponents
Select Case c.Type
Case vbext_ct_ClassModule, vbext_ct_Document
sfx = ".cls"
OType = acModule
Case vbext_ct_MSForm
sfx = ".frm"
OType = acForm
Case vbext_ct_StdModule
sfx = ".bas"
OType = acModule
Case Else
sfx = ""
End Select
If sfx <> "" And StrComp(Left(c.Name, 2), "om", vbBinaryCompare) = 0 Then
oName = c.Name
fn = path & "\" & oName & sfx
If gFso.FileExists(fn) Then
Set cNew = Application.VBE.VBProjects(1).VBComponents.import(fn)
'DoCmd.DeleteObject oType, oName
'cNew.Name = oName
'DoCmd.Save oType, objectname:=oName
If deleteAfterUpdate Then
gFso.DeleteFile fn
End If
End If
End If
Next c
End Sub
' RemoveEqualFiles "C:\Users\JaRa\OneDrive\Shared\Kybucs\LibraryCompare\","C:\Users\JaRa\OneDrive\Shared\Kybucs\Library\"
Public Sub RemoveEqualFiles(sourcePath As String, destinationPath As String, Optional moveFile As Boolean = False)
Dim sFolder As Scripting.Folder
Dim sf As File
Dim DF As File
Dim sourceFound As Boolean
Dim i As Long
Dim destinationFilename As String
Dim sString As String
Dim dString As String
For Each DF In gFso.GetFolder(destinationPath).Files
destinationFilename = omFileFunctions.RemoveExtension(DF.Name)
i = 1
sourceFound = False
Set sFolder = gFso.GetFolder(sourcePath)
For Each sf In sFolder.Files
If InStr(1, sf.Name, destinationFilename) = 1 Then
'dString = omFileFunctions.ReadFileToString(DF.path)
'sString = omFileFunctions.ReadFileToString(sf.path)
'sString = LCase(omStringFunctions.CleanStringUsingPattern(sString))
'dString = LCase(omStringFunctions.CleanStringUsingPattern(dString))
If dString = sString Then
sf.Delete
Else
If moveFile Then
sf.Move gFso.BuildPath(destinationPath, sf.Name)
End If
End If
Exit For
End If
Next
Next
End Sub
Public Sub LoadFromText(objectType As AcObjectType, objectName As String, filename As String)
'Application.LoadFromText AcObjectType.acModule, "omLibraryFunctions", "\\sql01\data\ACenter\2007\ACenter_9002_JaRa_Updates\omLibraryFunctions.bas"
Application.LoadFromText objectType, objectName, filename
End Sub
Public Sub LoadAsAXL(objectType As AcObjectType, objectName As String, filename As String)
'Application.LoadFromText AcObjectType.acModule, "omLibraryFunctions", "\\sql01\data\ACenter\2007\ACenter_9002_JaRa_Updates\omLibraryFunctions.bas"
msgbox "Does not exist in version 2007"
'Application.LoadAsAXL objectType, objectName, fileName
End Sub
Public Sub SaveAsText(objectType As AcObjectType, objectName As String, filename As String)
'Application.SaveAsText AcObjectType.acModule, "omLibraryFunctions", "\\sql01\data\ACenter\2007\ACenter_9002_JaRa_Updates\omLibraryFunctions.bas"
Application.SaveAsText objectType, objectName, filename
End Sub
Public Sub SaveAsAXL(objectType As AcObjectType, objectName As String, filename As String)
'Application.SaveAsText AcObjectType.acModule, "omLibraryFunctions", "\\sql01\data\ACenter\2007\ACenter_9002_JaRa_Updates\omLibraryFunctions.bas"
msgbox "Does not exist in version 2007"
'Application.SaveAsAXL objectType, objectName, fileName
End Sub
Public Sub ExportFormControlProperties(FormName As String, Optional WriteToFile As Boolean = False, Optional controlEscaped As Boolean = False)
Dim F As Form
Dim c As Control
Dim S1 As String
Dim S2 As String
Dim cEscapedStart As String
Dim cEscapedEnd As String
Dim cName As String
If controlEscaped Then
cEscapedStart = "Controls(" & Chr(34)
cEscapedEnd = Chr(34) & ")"
End If
DoCmd.OpenForm FormName, acDesign, , , , acHidden
Set F = Forms(FormName)
S1 = "Public Sub SetDefaultControlProperties()" & vbCrLf
S2 = "Public Sub SetMinimumControlProperties(minTop as long, minLeft as long, minWidth as long, minHeight as long)" & vbCrLf
For Each c In F.Controls
S1 = S1 & "' ------ " & c.Name & vbCrLf
cName = cEscapedStart & c.Name & cEscapedEnd
S1 = S1 & "me." & cName & ".Visible=" & c.Visible & vbCrLf
S1 = S1 & "me." & cName & ".Top=" & c.Top & vbCrLf
S1 = S1 & "me." & cName & ".Left=" & c.Left & vbCrLf
S1 = S1 & "me." & cName & ".Width=" & c.Width & vbCrLf
S1 = S1 & "me." & cName & ".Height=" & c.height & vbCrLf
S2 = S2 & "' ------ " & c.Name & vbCrLf
S2 = S2 & "me." & cName & ".Visible=false" & vbCrLf
S2 = S2 & "me." & cName & ".Top=minTop" & vbCrLf
S2 = S2 & "me." & cName & ".Left=minLeft" & vbCrLf
S2 = S2 & "me." & cName & ".Width=minWidth" & vbCrLf
S2 = S2 & "me." & cName & ".Height=minHeight" & vbCrLf
Next
S1 = S1 & "End Sub" & vbCrLf
S2 = S2 & "End Sub" & vbCrLf
If WriteToFile Then
omFileFunctions.WriteStringToFile gFso.BuildPath(CurrentProject.path, "ExportFormControlProperties_" & FormName & InternalGetTimeStamp()) & ".txt", S1 & vbCrLf & S2
Else
Debug.Print S1 & vbCrLf & S2
End If
DoCmd.Close acForm, FormName, acSaveNo
End Sub
Public Sub Dump(Optional objectType As AcObjectType = AcObjectType.acDefault, Optional silentMode As Boolean = True, Optional destinationPath As String, Optional addTimeStamp As Boolean = True)
Dim path As String
Dim O As Object
Dim currentPath As String
Dim rs As New ADODB.Recordset
If Len(Trim(Nz(destinationPath, ""))) <> 0 Then
path = destinationPath
Else
path = gFso.BuildPath(CurrentProject.path, "Dump")
End If
If addTimeStamp Then
path = IIf(Right(path, 1) = "\", Left(path, Len(path) - 1), path) & InternalGetTimeStamp()
End If
omFileFunctions.CreateFolderPath path
If objectType = acTable Or objectType = acDefault Then
currentPath = gFso.BuildPath(path, "Tables")
omFileFunctions.DeleteFolder currentPath
omFileFunctions.CreateFolderPath currentPath
rs.Open "SELECT T.Name FROM MSysObjects T WHERE T.Type=1 AND T.Flags=0", CurrentProject.connection, adOpenForwardOnly, adLockReadOnly
While Not rs.EOF
Application.ExportXml acExportTable, Rs("Name"), gFso.BuildPath(currentPath, Rs("Name") & ".xml"), gFso.BuildPath(currentPath, Rs("Name") & "_Schema.xml"), , , , acExportAllTableAndFieldProperties + acEmbedSchema
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
End If
If objectType = acQuery Or objectType = acDefault Then
currentPath = gFso.BuildPath(path, "Queries")
omFileFunctions.DeleteFolder currentPath
omFileFunctions.CreateFolderPath currentPath
For Each O In Application.CodeData.AllQueries
omLibraryFunctions.SaveAsText acQuery, O.Name, gFso.BuildPath(currentPath, O.Name & ".txt")
Next
End If
If objectType = acForm Or objectType = acDefault Then
currentPath = gFso.BuildPath(path, "Forms")
omFileFunctions.DeleteFolder currentPath
omFileFunctions.CreateFolderPath currentPath
For Each O In Application.CodeProject.AllForms
omLibraryFunctions.SaveAsText acForm, O.Name, gFso.BuildPath(currentPath, O.Name & ".txt")
Next
End If
If objectType = acReport Or objectType = acDefault Then
currentPath = gFso.BuildPath(path, "Reports")
omFileFunctions.DeleteFolder currentPath
omFileFunctions.CreateFolderPath currentPath
For Each O In Application.CodeProject.AllReports
omLibraryFunctions.SaveAsText acReport, O.Name, gFso.BuildPath(currentPath, O.Name & ".txt")
Next
End If
If objectType = acModule Or objectType = acDefault Then
currentPath = gFso.BuildPath(path, "Modules")
omFileFunctions.DeleteFolder currentPath
omFileFunctions.CreateFolderPath currentPath
For Each O In Application.CodeProject.AllModules
omLibraryFunctions.SaveAsText acModule, O.Name, gFso.BuildPath(currentPath, O.Name & ".txt")
Next
End If
If objectType = acMacro Or objectType = acDefault Then
currentPath = gFso.BuildPath(path, "Macros")
omFileFunctions.DeleteFolder currentPath
omFileFunctions.CreateFolderPath currentPath
For Each O In Application.CodeProject.AllMacros
omLibraryFunctions.SaveAsText acMacro, O.Name, gFso.BuildPath(currentPath, O.Name & ".txt")
Next
End If
If Not silentMode Then
msgbox "Completed", vbOKOnly
End If
End Sub
Public Sub DumpImport(objectType As AcObjectType, Optional silentMode As Boolean = True, Optional sourcePath As String)
Dim path As String
Dim O As Object
Dim currentPath As String
Dim fso As New FileSystemObject
Dim F As File
Dim i As Long
Dim tableName As String
If Len(Trim(Nz(sourcePath, ""))) <> 0 Then
path = sourcePath
Else
path = gFso.BuildPath(CurrentProject.path, "Dump")
End If
Select Case objectType
Case acTable
currentPath = fso.BuildPath(path, "Tables")
For Each F In fso.GetFolder(currentPath).Files
If InStr(1, F.Name, "_Schema") = 0 Then
If Not silentMode Then
Debug.Print "start : " & F.Name
DoEvents
End If
tableName = Left(F.Name, Len(F.Name) - 4)
For i = 0 To CurrentData.AllTables.Count - 1
If CurrentData.AllTables(i).Name = tableName Then
DoCmd.Rename tableName & "_" & Format(Now, "yyyymmdd_hhnnss"), acTable, tableName
End If
Next
Application.ImportXML F.path, acStructureAndData
End If
Next
Case acModule
currentPath = fso.BuildPath(path, "Modules")
For Each F In fso.GetFolder(currentPath).Files
If F.Name <> "omLibraryFunctions.txt" Then
If Not silentMode Then
Debug.Print "start : " & F.Name
DoEvents
End If
omLibraryFunctions.LoadFromText acModule, Left(F.Name, Len(F.Name) - 4), F.path
End If
Next
Case acQuery
currentPath = fso.BuildPath(path, "Queries")
For Each F In fso.GetFolder(currentPath).Files
If Not silentMode Then
Debug.Print "start : " & F.Name
DoEvents
End If
omLibraryFunctions.LoadFromText acQuery, Left(F.Name, Len(F.Name) - 4), F.path
Next
Case acForm
currentPath = fso.BuildPath(path, "Forms")
For Each F In fso.GetFolder(currentPath).Files
If Not silentMode Then
Debug.Print "start : " & F.Name
DoEvents
End If
omLibraryFunctions.LoadFromText acForm, Left(F.Name, Len(F.Name) - 4), F.path
Next
Case acReport
currentPath = fso.BuildPath(path, "Reports")
For Each F In fso.GetFolder(currentPath).Files
If Not silentMode Then
Debug.Print "start : " & F.Name
DoEvents
End If
omLibraryFunctions.LoadFromText acReport, Left(F.Name, Len(F.Name) - 4), F.path
Next
Case acMacro
currentPath = fso.BuildPath(path, "Macros")
For Each F In fso.GetFolder(currentPath).Files
If Not silentMode Then
Debug.Print "start : " & F.Name
DoEvents
End If
omLibraryFunctions.LoadFromText acMacro, Left(F.Name, Len(F.Name) - 4), F.path
Next
End Select
If Not silentMode Then
msgbox "Completed", vbOKOnly
End If
End Sub
Public Sub DeleteByObjectType(objectType As AcObjectType, Optional silentMode As Boolean = True, Optional maxNumberOfObjects = 0)
Dim cnt As Long
Dim cntTo As Long
Dim i As Long
Select Case objectType
Case acModule
cnt = Application.CodeProject.AllModules.Count - 1
For i = cnt To 0 Step -1
DoCmd.DeleteObject objectType, Application.CodeProject.AllModules(i).Name
Next
Case acQuery
cnt = Application.CodeData.AllQueries.Count - 1
For i = cnt To 0 Step -1
DoCmd.DeleteObject objectType, Application.CodeData.AllQueries(i).Name
Next
Case acForm
cnt = Application.CodeProject.AllForms.Count - 1
cntTo = IIf(maxNumberOfObjects = 0, 0, cnt - maxNumberOfObjects)
cntTo = IIf(cntTo < 0, 0, cntTo)
For i = cnt To cntTo Step -1
DoCmd.DeleteObject objectType, Application.CodeProject.AllForms(i).Name
Next
Case acReport
cnt = Application.CodeProject.AllReports.Count - 1
cntTo = IIf(maxNumberOfObjects = 0, 0, cnt - maxNumberOfObjects)
cntTo = IIf(cntTo < 0, 0, cntTo)
For i = cnt To cntTo Step -1
DoCmd.DeleteObject objectType, Application.CodeProject.AllReports(i).Name
Next
Case acMacro
cnt = Application.CodeProject.AllMacros.Count - 1
For i = cnt To 0 Step -1
DoCmd.DeleteObject objectType, Application.CodeProject.AllMacros(i).Name
Next
End Select
If Not silentMode Then
MsgBox "Completed", vbOKOnly
End If
End Sub
Public Sub VBACountModules()
Dim cnt As Long
cnt = VBE.ActiveVBProject.VBComponents.Count
msgbox "Access Project contains #" & cnt & " modules.", vbOKOnly
' 20200512 : 1176 modules
End Sub
Public Sub VBACountLines()
Dim cnt As Long
Dim F As VBIDE.VBComponent
For Each F In VBE.ActiveVBProject.VBComponents
cnt = cnt + F.CodeModule.CountOfLines
Next
msgbox "Access Project contains #" & cnt & " lines.", vbOKOnly
End Sub
Public Sub VBAFindReplace(findString As String, replaceString As String, Optional silentMode As Boolean = True)
Dim c As VBIDE.VBComponent
Dim i As Long
Dim S As String
For Each c In VBE.ActiveVBProject.VBComponents
For i = 1 To c.CodeModule.CountOfLines
S = c.CodeModule.Lines(i, 1)
If InStr(1, S, findString) > 0 Then
If Not silentMode Then
Debug.Print "In module: " & c.Name & " -> replaced: " & S
End If
c.CodeModule.ReplaceLine i, Replace(S, findString, replaceString)
End If
Next i
Next
End Sub
Public Sub ListOnlyModulesWithoutLines()
Dim F As VBComponent
For Each F In VBE.ActiveVBProject.VBComponents
If F.CodeModule.CountOfLines = F.CodeModule.CountOfDeclarationLines Then
Debug.Print F.Name
End If
Next
End Sub
Public Sub RemoveModulesWithoutLines(Optional silentMode As Boolean = True)
Dim F As VBIDE.VBComponent
Dim S As String
Dim i As Long
Dim msg As String
Dim msgBoxResult As VbMsgBoxResult
For i = VBE.ActiveVBProject.VBComponents.Count To 1 Step -1
Set F = VBE.ActiveVBProject.VBComponents(i)
If F.CodeModule.CountOfLines = F.CodeModule.CountOfDeclarationLines And F.CodeModule.CountOfLines < 3 Then
msg = F.Name
If F.CodeModule.CountOfLines > 0 Then
msg = msg & vbCrLf & F.CodeModule.Lines(1, F.CodeModule.CountOfLines)
End If
'Debug.Print msg
If Not silentMode Then
msgBoxResult = msgbox(msg & vbCrLf & vbCrLf & "Delete CodeModule for " & F.Name, vbYesNo)
Else
msgBoxResult = vbYes
End If
If msgBoxResult = vbYes Then
If F.Type = vbext_ct_ClassModule Or F.Type = vbext_ct_StdModule Then
VBE.ActiveVBProject.VBComponents.Remove F
ElseIf Left(F.Name, Len("Report_")) = "Report_" Then
S = Mid(F.Name, Len("Report_") + 1)
DoCmd.OpenReport S, acDesign
Reports(S).HasModule = False
DoCmd.Close acReport, S, acSaveYes
ElseIf Left(F.Name, Len("Form_")) = "Form_" Then
S = Mid(F.Name, Len("Form_") + 1)
DoCmd.OpenForm S, acDesign
Forms(S).HasModule = False
DoCmd.Close acForm, S, acSaveYes
End If
End If
End If
Next
End Sub
Public Sub DumpAndCommitAndPush(Optional objectType As AcObjectType = AcObjectType.acDefault)
Dim path As String
Dim msg As String
path = gFso.BuildPath(omFileFunctions.GetUserRootFolder, "Source\Repos\ACenter\")
omLibraryFunctions.Dump objectType, True, path, False
omLibraryFunctions.CommitAndPush path
End Sub
Public Sub CommitAndPush(repositoryPath As String)
Dim path As String
Dim fn As String
Dim S As String
Dim commitMessage As String
Dim gitFolder As String
gitFolder = "C:\Program Files\Git\"
If gFso.FolderExists(gitFolder) = False Then
gitFolder = gFso.BuildPath(omFileFunctions.GetUserRootFolder, "AppData\Local\Programs\Git\")
End If
commitMessage = InputBox("Geef een omschrijving")
If Len(commitMessage) = 0 Then
MsgBox "Not message was given. Execution is aborted!", vbOKOnly
Exit Sub
End If
fn = gFso.BuildPath(repositoryPath, ".git\COMMITMESSAGE")
omFileFunctions.WriteStringToFile fn, commitMessage
S = "cd '{{repositoryPath}}'"
S = S & vbCrLf & "'{{GitFolder}}bin\git.exe' add -A"
S = S & vbCrLf & "'{{GitFolder}}bin\git.exe' commit -F '{{FilenameCommitMessage}}'"
S = S & vbCrLf & "'{{GitFolder}}bin\git.exe' push"
S = Replace(S, "{{repositoryPath}}", repositoryPath)
S = Replace(S, "{{GitFolder}}", gitFolder)
S = Replace(S, "{{FilenameCommitMessage}}", fn)
S = Replace(S, "'", Chr(34))
fn = gFso.BuildPath(CurrentProject.path, CurrentProject.Name & "_CommitAndPush.bat")
omFileFunctions.WriteStringToFile fn, S
Shell fn
End Sub
Public Sub RemoveDeletedObjects()
Dim rs As New ADODB.Recordset
Dim objType As AcObjectType
rs.Open "SELECT Name,Type FROM MSysobjects WHERE Name LIKE '~%'", CurrentProject.connection, adOpenForwardOnly, adLockReadOnly
While Not rs.EOF
objType = -1
Select Case rs("Type")
Case 4
objType = acTable
Case 5
objType = acQuery
Case -32766
objType = acMacro
Case Else
objType = 0
MsgBox "ObjectType Not Defined " & rs("type")
End Select
If objType > -1 Then
DoCmd.DeleteObject objType, rs("Name")
End If
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
End Sub
Public Sub ListFormsToTable(Optional tableName As String = "___T_Forms")
Dim rs As New ADODB.Recordset
Dim F As AccessObject
rs.Open tableName, CurrentProject.connection, adOpenForwardOnly, adLockOptimistic
For Each F In CodeProject.AllForms
rs.AddNew
rs("Name") = F.Name
rs.Update
Next
rs.Close
Set rs = Nothing
End Sub
Public Sub CreateBinaryColumns()
Dim td As DAO.TableDef
Dim db As DAO.Database
Dim fd As Field
Set db = CurrentDb
Set td = db.TableDefs("Table1")
Set fd = td.CreateField("BinaryColumn", DataTypeEnum.dbBinary, 100)
fd.Attributes = fd.Attributes Or dbFixedField
td.Fields.Append fd
Set fd = td.CreateField("VarbinaryColumn", DataTypeEnum.dbBinary, 100)
td.Fields.Append fd
td.Fields.Refresh
db.TableDefs.Refresh
End Sub
Public Function GenerateDataMacroAfterInsert(tableName As String) As String
Dim s As String
Dim statementActionTemplate As String
Dim statements As String
Dim f As Field
Dim cdb As Database
statementActionTemplate = "<Action Name='SetField'>" & vbCrLf
statementActionTemplate = statementActionTemplate + "<Argument Name='Field'><!FieldName!></Argument>" & vbCrLf
statementActionTemplate = statementActionTemplate + "<Argument Name='Value'>[<!TableName!>].[<!FieldName!>]</Argument>" & vbCrLf
statementActionTemplate = statementActionTemplate + "</Action>"
statementActionTemplate = Replace(statementActionTemplate, "'", Chr(34))
s = "<?xml version='1.0' encoding='UTF-16' standalone='no'?>" & vbCrLf
s = s + "<DataMacros xmlns='http://schemas.microsoft.com/office/accessservices/2009/11/application'>" & vbCrLf
s = s + "<DataMacro Event='AfterInsert'>" & vbCrLf
s = s + "<Statements>" & vbCrLf
s = s + "<CreateRecord>" & vbCrLf
s = s + "<Data>" & vbCrLf
s = s + "<Reference>Log_<!TableName!></Reference>" & vbCrLf
s = s + "</Data>" & vbCrLf
s = s + "<Statements>" & vbCrLf
s = s + "<!Statements!>"
s = s + "</Statements>" & vbCrLf
s = s + "</CreateRecord>" & vbCrLf
s = s + "</Statements>" & vbCrLf
s = s + "</DataMacro>" & vbCrLf
s = s + "</DataMacros>"
s = Replace(s, "'", Chr(34))
s = Replace(s, "<!TableName!>", tableName)
Set cdb = CurrentDb
For Each f In cdb.TableDefs(tableName).Fields
statements = statements + Replace(Replace(statementActionTemplate, "<!FieldName!>", f.Name), "<!TableName!>", tableName) & vbCrLf
Next
GenerateDataMacroAfterInsert = Replace(s, "<!Statements!>", statements)
End Function
Public Function GenerateDataMacroAfterUpdate(tableName As String) As String
Dim s As String
Dim statementActionTemplate As String
Dim statements As String
Dim f As Field
Dim cdb As Database
statementActionTemplate = "<Action Name='SetField'>" & vbCrLf
statementActionTemplate = statementActionTemplate + "<Argument Name='Field'><!FieldName!></Argument>" & vbCrLf
statementActionTemplate = statementActionTemplate + "<Argument Name='Value'>[<!TableName!>].[<!FieldName!>]</Argument>" & vbCrLf
statementActionTemplate = statementActionTemplate + "</Action>"
statementActionTemplate = Replace(statementActionTemplate, "'", Chr(34))
s = "<?xml version='1.0' encoding='UTF-16' standalone='no'?>" & vbCrLf
s = s + "<DataMacros xmlns='http://schemas.microsoft.com/office/accessservices/2009/11/application'>" & vbCrLf
s = s + "<DataMacro Event='AfterUpdate'>" & vbCrLf
s = s + "<Statements>" & vbCrLf
s = s + "<CreateRecord>" & vbCrLf
s = s + "<Data>" & vbCrLf
s = s + "<Reference>Log_<!TableName!></Reference>" & vbCrLf
s = s + "</Data>" & vbCrLf
s = s + "<Statements>" & vbCrLf
s = s + "<!Statements!>"
s = s + "</Statements>" & vbCrLf
s = s + "</CreateRecord>" & vbCrLf
s = s + "</Statements>" & vbCrLf
s = s + "</DataMacro>" & vbCrLf
s = s + "</DataMacros>"
s = Replace(s, "'", Chr(34))
s = Replace(s, "<!TableName!>", tableName)
Set cdb = CurrentDb
For Each f In cdb.TableDefs(tableName).Fields
statements = statements + Replace(Replace(statementActionTemplate, "<!FieldName!>", f.Name), "<!TableName!>", tableName) & vbCrLf
Next
GenerateDataMacroAfterUpdate = Replace(s, "<!Statements!>", statements)
End Function