Skip to content

Commit 6741e8a

Browse files
committed
Start procedure for call from MSAccessVCS (with add-in call customization)
1 parent ee0efc0 commit 6741e8a

File tree

4 files changed

+94
-42
lines changed

4 files changed

+94
-42
lines changed

source/forms/DeclarationDictForm.cls

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -299,53 +299,21 @@ End Sub
299299

300300
Private Sub SaveToTable()
301301

302-
Dim db As DAO.Database
303-
Set db = CurrentDb
304-
305-
If Not TableDefExists("USysDeclDict", db) Then
306-
db.Execute "create table USysDeclDict (DeclWord varchar(255) Not Null Primary Key)", dbFailOnError
307-
End If
308-
309-
Dim rs As DAO.Recordset
310-
Dim i As Long
311-
312-
db.Execute "delete from USysDeclDict"
313-
Set rs = db.OpenRecordset("USysDeclDict", dbOpenDynaset, dbAppendOnly)
314-
For i = 0 To m_DeclarationDict.Count - 1
315-
rs.AddNew
316-
rs.Fields(0).Value = m_DeclarationDict.VariationsDict.Keys(i)
317-
rs.Update
318-
Next
319-
320-
ShowTableRecInfo m_DeclarationDict.Count & " records were inserted into USysDeclDict"
302+
m_DeclarationDict.SaveToTable DefaultDeclDictTableName
303+
ShowTableRecInfo m_DeclarationDict.Count & " records were inserted into " & DefaultDeclDictTableName
321304

322305
End Sub
323306

324307
Private Sub LoadFromTable()
325308

326-
Dim db As DAO.Database
327-
Dim rs As DAO.Recordset
328-
Dim i As Long
309+
Dim ErrMsg As String
329310

330-
Set db = CurrentDb
331-
332-
If Not TableDefExists("USysDeclDict", db) Then
333-
ShowTableRecInfo "Table USysDeclDict not exists"
311+
If Not m_DeclarationDict.LoadFromTable(DefaultDeclDictTableName, ErrMsg) Then
312+
ShowTableRecInfo ErrMsg
334313
Exit Sub
335314
End If
336315

337-
Set m_DeclarationDict = New DeclarationDict
338-
339-
340-
Set rs = db.OpenRecordset("select DeclWord from USysDeclDict", dbOpenSnapshot)
341-
Do While Not rs.EOF
342-
m_DeclarationDict.AddWord rs.Fields(0)
343-
rs.MoveNext
344-
Loop
345-
rs.Close
346-
Set db = Nothing
347-
348-
ShowTableRecInfo m_DeclarationDict.Count & " records were imported from USysDeclDict"
316+
ShowTableRecInfo m_DeclarationDict.Count & " records were imported from " & DefaultDeclDictTableName
349317
RequeryDictData
350318

351319
End Sub

source/modules/DeclarationDict.cls

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,61 @@ Public Sub ChangeKeyLetterCase(ByVal WordWithNewLetterCase As String)
445445

446446
End Sub
447447

448-
Public Sub LoadFromFile(ByVal FullFileName As String)
448+
Public Function LoadFromTable(ByVal TableName As String, Optional ByRef ErrorMsg As String) As Boolean
449+
450+
Dim db As DAO.Database
451+
Dim rs As DAO.Recordset
452+
Dim i As Long
453+
454+
Set db = CurrentDb
455+
456+
If Not TableDefExists(TableName, db) Then
457+
ErrorMsg = "Table " & TableName & " not exists"
458+
LoadFromTable = False
459+
Exit Function
460+
End If
461+
462+
Set rs = db.OpenRecordset("select DeclWord from " & TableName, dbOpenSnapshot)
463+
Do While Not rs.EOF
464+
AddWord rs.Fields(0)
465+
rs.MoveNext
466+
Loop
467+
rs.Close
468+
Set db = Nothing
469+
470+
LoadFromTable = True
471+
472+
End Function
473+
474+
Public Sub SaveToTable(ByVal TableName As String)
475+
476+
Dim db As DAO.Database
477+
Set db = CurrentDb
478+
479+
If Not TableDefExists(TableName, db) Then
480+
db.Execute "create table " & TableName & " (DeclWord varchar(255) Not Null Primary Key)", dbFailOnError
481+
End If
482+
483+
Dim rs As DAO.Recordset
484+
Dim i As Long
485+
486+
db.Execute "delete from " & TableName
487+
Set rs = db.OpenRecordset(TableName, dbOpenDynaset, dbAppendOnly)
488+
For i = 0 To m_Words.Count - 1
489+
rs.AddNew
490+
rs.Fields(0).Value = m_Words.Keys(i)
491+
rs.Update
492+
Next
493+
494+
End Sub
495+
496+
Public Function LoadFromFile(ByVal FullFileName As String, Optional ByRef ErrorMsg As String) As Boolean
497+
498+
If Not FileExists(FullFileName) Then
499+
LoadFromFile = False
500+
ErrorMsg = "File " & FullFileName & " not exists"
501+
Exit Function
502+
End If
449503

450504
With New ADODB.Stream
451505
.Charset = "utf-8"
@@ -457,7 +511,9 @@ Public Sub LoadFromFile(ByVal FullFileName As String)
457511
.Close
458512
End With
459513

460-
End Sub
514+
LoadFromFile = True
515+
516+
End Function
461517

462518
Public Sub ExportToFile(ByVal FullFileName As String)
463519

source/modules/_AddInAPI.bas

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,34 @@ Public Function StartAddIn()
88

99
End Function
1010

11-
Public Function RunVcsCheck()
11+
Public Function RunVcsCheck() As Variant
1212

13+
Dim DictFilePath As String
14+
15+
With New DeclarationDict
16+
17+
If Not .LoadFromTable(DefaultDeclDictTableName) Then
18+
DictFilePath = CurrentProject.Path & "\DeclarationDict.txt"
19+
If Not .LoadFromFile(DictFilePath) Then
20+
.ImportVBProject CurrentVbProject
21+
' ... log info: first export
22+
Debug.Print "RunVcsCheck: no export data exists, run first export"
23+
.ExportToFile DictFilePath
24+
RunVcsCheck = "Info: no export data exists, run first export"
25+
Exit Function
26+
End If
27+
End If
28+
29+
.ImportVBProject CurrentVbProject
30+
31+
If .DiffCount > 0 Then
32+
RunVcsCheck = "Failed: " & .DiffCount & " words with different letter case"
33+
Debug.Print "RunVcsCheck: " & .DiffCount & " words with different letter case"
34+
Else
35+
RunVcsCheck = True
36+
End If
37+
38+
End With
1339

1440

1541
End Function

source/modules/_config_Application.bas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Option Explicit
1818
Option Private Module
1919

2020
'Version number
21-
Private Const APPLICATION_VERSION As String = "0.2.1.250304"
21+
Private Const APPLICATION_VERSION As String = "0.3.0.250305"
2222

2323
Private Const APPLICATION_NAME As String = "ACLib Declaration Dictionary"
2424
Private Const APPLICATION_FULLNAME As String = "Access-CodeLib - Declaration Dictionary"
@@ -28,6 +28,8 @@ Private Const APPLICATION_STARTFORMNAME As String = "DeclarationDictForm"
2828

2929
Private m_Extensions As Object 'ApplicationHandler_ExtensionCollection
3030

31+
Public Const DefaultDeclDictTableName As String = "USysDeclDict"
32+
3133
'---------------------------------------------------------------------------------------
3234
' Sub: InitConfig
3335
'---------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)