Skip to content

Commit 10f80ab

Browse files
Refactor table data listing/filtering in options
Refactored the code that pulls a list of the tables in the current database so the user can specify the tables from which they want to export data as part of the export process. Bitwise operators are not supported in Microsoft Access SQL queries, so this logic has been moved to VBA instead. Additionally, some system tables that cannot be viewed or modified have been excluded from the table listing. I also adjusted the number captions to reflect the number of items hidden/displayed in the current context. (This seemed to be the most logically intuitive number to display.) #403
1 parent cd020eb commit 10f80ab

File tree

5 files changed

+171
-106
lines changed

5 files changed

+171
-106
lines changed

Version Control.accda.src/forms/frmVCSOptions.bas

+137-101
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Begin Form
1616
Width =10080
1717
DatasheetFontHeight =11
1818
ItemSuffix =241
19-
Left =20761
20-
Top =2250
21-
Right =-29055
22-
Bottom =13995
19+
Left =3225
20+
Top =2430
21+
Right =18945
22+
Bottom =14175
2323
RecSrcDt = Begin
2424
0x79e78b777268e540
2525
End
@@ -3435,6 +3435,7 @@ Private Enum eTableCol
34353435
etcSystem = 3
34363436
etcOther = 4
34373437
etcLocal = 5
3438+
etcLinked = 6
34383439
End Enum
34393440

34403441
Private Enum eMapAction
@@ -3520,76 +3521,89 @@ Private Sub LoadTableList()
35203521
Dim intFormat As eTableDataExportFormat
35213522
Dim strName As String
35223523
Dim lngColumn As eTableCol
3524+
Dim dbs As DAO.Database
3525+
Dim rstTableData As DAO.Recordset
3526+
Dim rstSource As DAO.Recordset
3527+
Dim strSql As String
3528+
Dim fld As DAO.Field
3529+
Dim lngFlags As Long
3530+
Dim lngType As Long
35233531

35243532
' Reset list of tables
3525-
CodeDb.Execute "DELETE FROM tblTableData;", dbFailOnError
3526-
3533+
Set dbs = CodeDb
3534+
dbs.Execute "DELETE FROM tblTableData;", dbFailOnError
3535+
3536+
' Open table to load records
3537+
Set rstTableData = dbs.OpenRecordset("SELECT * FROM tblTableData;", dbOpenDynaset)
3538+
35273539
' Get list of tables if we have a database file open.
35283540
If DatabaseFileOpen Then
3529-
Dim strSql As String
3530-
Dim rsSource As DAO.Recordset
3531-
Dim rsTableData As DAO.Recordset
3532-
Dim fld As DAO.Field
3533-
3541+
3542+
' Note that Access SQL does not support bitwise "and" operator
3543+
' (Also known as BAND in ADO) so we will check the bit flags in VBA instead.
35343544
strSql = _
3535-
"SELECT " & _
3536-
" o.Name AS TableName, " & _
3537-
" IIf(o.Flags And -2147483646 = -2147483646, 1, 0) AS IsSystem, " & _
3538-
" IIf(o.Flags And 1 = 1, 1, 0) AS IsHidden, " & _
3539-
" IIf(o.Type = 1, 1, 0) AS IsLocal, " & _
3540-
" IIf(o.Type <> 1, 1, 0) AS IsOther " & _
3545+
"SELECT o.Name, o.Type, o.Flags " & _
35413546
"FROM MSysObjects AS o " & _
35423547
"WHERE o.Type IN (1, 4, 6) " & _
35433548
"ORDER BY o.Name;"
3544-
Set rsSource = CurrentDb.OpenRecordset(strSql, dbOpenSnapshot)
3545-
Set rsTableData = CodeDb.OpenRecordset("SELECT * FROM tblTableData;", dbOpenDynaset)
3546-
3547-
Do Until rsSource.EOF
3548-
rsTableData.AddNew
3549-
For Each fld In rsSource.Fields
3550-
rsTableData.Fields(fld.Name).Value = fld.Value
3551-
Next
3552-
Select Case True
3553-
Case Nz(rsSource.Fields("IsSystem").Value, False)
3554-
lngColumn = etcSystem
3555-
Case Nz(rsSource.Fields("IsLocal").Value, False)
3556-
lngColumn = etcLocal
3557-
Case Nz(rsSource.Fields("IsOther").Value, False)
3558-
lngColumn = etcOther
3559-
Case Else
3560-
lngColumn = -1
3561-
End Select
3562-
rsTableData.Fields("TableIcon").Value = GetTableIcon(lngColumn)
3563-
rsTableData.Update
3564-
rsSource.MoveNext
3565-
Loop
3566-
3567-
' Add in the list of saved tables, adding into the sorted location
3568-
If Not Options.TablesToExportData Is Nothing Then
3569-
' Loop through each table in the saved table list
3570-
For Each varKey In Options.TablesToExportData.Keys
3571-
strName = CStr(varKey)
3572-
strFormat = Options.TablesToExportData.Item(varKey)("Format")
3573-
intFormat = Options.GetTableExportFormat(strFormat)
3574-
3575-
With rsTableData
3576-
.FindFirst "[TableName]='" & Replace$(strName, "'", "''") & "'"
3577-
If .EOF Then
3578-
.AddNew
3579-
.Fields("TableName").Value = strName
3580-
.Fields("TableIcon").Value = GetTableIcon(etcOther)
3581-
.Fields("FormatType").Value = intFormat
3582-
.Fields("IsOther").Value = True
3583-
.Update
3584-
Else
3585-
.Edit
3586-
.Fields("FormatType").Value = intFormat
3587-
.Update
3588-
End If
3589-
End With
3590-
Next varKey
3591-
End If
3549+
3550+
Set rstSource = CurrentDb.OpenRecordset(strSql, dbOpenSnapshot)
3551+
With rstSource
3552+
Do While Not .EOF
3553+
' Determine type of table
3554+
lngFlags = Nz(!Flags, 0)
3555+
lngType = Nz(!Type, 0)
3556+
If (lngFlags < 0) Or BitSet(lngFlags, 1) Then
3557+
' Don't include read-only or deeply hidden system tables.
3558+
' https://isladogs.co.uk/purpose-of-system-tables-2/index.html#TFE
3559+
Else
3560+
rstTableData.AddNew
3561+
rstTableData!TableName = Nz(!Name)
3562+
rstTableData!Flags = Nz(!Flags)
3563+
rstTableData!IsSystem = ((lngFlags <> 0) And (lngFlags <> 8) And (lngType = 1))
3564+
rstTableData!IsHidden = BitSet(lngFlags, 8)
3565+
rstTableData!IsLocal = (lngType = 1)
3566+
' Determine table icon
3567+
rstTableData!TableIcon = GetTableIcon(etcLinked) ' Default to linked table if no match.
3568+
If rstTableData!IsLocal Then rstTableData!TableIcon = GetTableIcon(etcLocal)
3569+
If rstTableData!IsSystem Then rstTableData!TableIcon = GetTableIcon(etcSystem)
3570+
rstTableData.Update
3571+
End If
3572+
.MoveNext
3573+
Loop
3574+
.Close
3575+
End With
3576+
End If
3577+
3578+
' Add in the list of saved tables, adding into the sorted location
3579+
If Not Options.TablesToExportData Is Nothing Then
3580+
' Loop through each table in the saved table list
3581+
For Each varKey In Options.TablesToExportData.Keys
3582+
strName = CStr(varKey)
3583+
strFormat = Options.TablesToExportData.Item(varKey)("Format")
3584+
intFormat = Options.GetTableExportFormat(strFormat)
3585+
3586+
With rstTableData
3587+
.FindFirst "[TableName]='" & Replace$(strName, "'", "''") & "'"
3588+
If .NoMatch Then
3589+
.AddNew
3590+
!TableName = strName
3591+
!TableIcon = GetTableIcon(etcOther)
3592+
!FormatType = intFormat
3593+
!IsOther = True
3594+
.Update
3595+
Else
3596+
.Edit
3597+
!FormatType = intFormat
3598+
.Update
3599+
End If
3600+
End With
3601+
Next varKey
35923602
End If
3603+
3604+
' Close recordset after adding records
3605+
rstTableData.Close
3606+
35933607
End Sub
35943608

35953609

@@ -3601,25 +3615,31 @@ End Sub
36013615
'---------------------------------------------------------------------------------------
36023616
'
36033617
Private Sub SaveTableList()
3604-
Dim rsTableData As DAO.Recordset
3605-
Dim dTables As Scripting.Dictionary
3606-
Dim dTable As Scripting.Dictionary
3618+
3619+
Dim rstTableData As DAO.Recordset
3620+
Dim dTables As Dictionary
3621+
Dim dTable As Dictionary
36073622

36083623
' Save list of tables to export data
3609-
Set dTables = New Scripting.Dictionary
3624+
Set dTables = New Dictionary
36103625
dTables.CompareMode = TextCompare
36113626

3612-
Set rsTableData = CodeDb.OpenRecordset("SELECT TableName, FormatType FROM tblTableData WHERE FormatType <> 0 ORDER BY TableName;", dbOpenForwardOnly)
3613-
Do Until rsTableData.EOF
3614-
Set dTable = New Scripting.Dictionary
3615-
dTable.CompareMode = TextCompare
3616-
dTable("Format") = Options.GetTableExportFormatName(rsTableData.Fields("FormatType").Value)
3617-
dTables.Add rsTableData.Fields("TableName").Value, dTable
3618-
3619-
rsTableData.MoveNext
3620-
Loop
3627+
Set rstTableData = CodeDb.OpenRecordset( _
3628+
"SELECT TableName, FormatType FROM tblTableData " & _
3629+
"WHERE FormatType <> 0 ORDER BY TableName;", dbOpenForwardOnly)
3630+
With rstTableData
3631+
Do Until .EOF
3632+
Set dTable = New Dictionary
3633+
dTable.CompareMode = TextCompare
3634+
dTable("Format") = Options.GetTableExportFormatName(Nz(!FormatType, 0))
3635+
dTables.Add Nz(!TableName), dTable
3636+
.MoveNext
3637+
Loop
3638+
.Close
3639+
End With
36213640

36223641
Set Options.TablesToExportData = dTables
3642+
36233643
End Sub
36243644

36253645

@@ -3631,33 +3651,38 @@ End Sub
36313651
'---------------------------------------------------------------------------------------
36323652
'
36333653
Private Sub AddUpdateTableInList(strName As String, lngFormatType As eTableDataExportFormat, blnHidden As Boolean, blnSystem As Boolean, blnOther As Boolean, blnLocal As Boolean)
3634-
Dim rsClone As DAO.Recordset
3635-
Dim rsActive As DAO.Recordset
36363654

3637-
Set rsClone = Me.sfrmTableData.Form.RecordsetClone
3638-
Set rsActive = Me.sfrmTableData.Form.Recordset
3655+
Dim rstClone As DAO.Recordset
3656+
Dim rstActive As DAO.Recordset
36393657

3640-
With rsActive
3641-
rsClone.FindFirst "TableName='" & Replace$(strName, "'", "''") & "'"
3658+
Set rstClone = Me.sfrmTableData.Form.RecordsetClone
3659+
Set rstActive = Me.sfrmTableData.Form.Recordset
36423660

3643-
If rsClone.NoMatch Then
3661+
With rstActive
3662+
3663+
' Look for matching table name
3664+
rstClone.FindFirst "TableName='" & Replace$(strName, "'", "''") & "'"
3665+
If rstClone.NoMatch Then
3666+
' Add new table to this list
36443667
Me.sfrmTableData.Form.AllowAdditions = True
36453668
.AddNew
3646-
.Fields("TableName").Value = strName
3647-
.Fields("TableIcon").Value = GetTableIcon(etcOther)
3669+
!TableName = strName
3670+
!TableIcon = GetTableIcon(etcOther)
36483671
Else
3649-
.Bookmark = rsClone.Bookmark
3672+
.Bookmark = rstClone.Bookmark
36503673
.Edit
36513674
End If
36523675

3653-
.Fields("FormatType").Value = lngFormatType
3654-
.Fields("IsHidden").Value = blnHidden
3655-
.Fields("IsSystem").Value = blnSystem
3656-
.Fields("IsOther").Value = blnOther
3657-
.Fields("IsLocal").Value = blnLocal
3676+
' Update remaining fields
3677+
!FormatType = lngFormatType
3678+
!IsHidden = blnHidden
3679+
!IsSystem = blnSystem
3680+
!IsOther = blnOther
3681+
!IsLocal = blnLocal
36583682
.Update
36593683
Me.sfrmTableData.Form.AllowAdditions = False
36603684
End With
3685+
36613686
End Sub
36623687

36633688

@@ -3711,9 +3736,11 @@ Private Sub RefreshTableDisplay()
37113736

37123737
Me.sfrmTableData.Form.RecordSource = strSql
37133738

3714-
Me.lblTableShowHidden.Caption = GetCaptionWithCount("Show Hidden", "SELECT COUNT(d.TableName) FROM tblTableData AS d WHERE d.IsHidden <> 0 AND d.FormatType <> 0;")
3715-
Me.lblTableShowSystem.Caption = GetCaptionWithCount("Show System", "SELECT COUNT(d.TableName) FROM tblTableData AS d WHERE d.IsSystem <> 0 AND d.FormatType <> 0;")
3716-
Me.lblTableShowOther.Caption = GetCaptionWithCount("Show Other", "SELECT COUNT(d.TableName) FROM tblTableData AS d WHERE d.IsOther <> 0 AND d.FormatType <> 0;")
3739+
' Update captions with counts
3740+
Me.lblTableShowHidden.Caption = GetCaptionWithCount("Show Hidden", "d.IsHidden = True AND d.IsSystem = " & chkTableShowSystem)
3741+
Me.lblTableShowSystem.Caption = GetCaptionWithCount("Show System", "d.IsSystem = True AND d.IsHidden = " & chkTableShowHidden)
3742+
Me.lblTableShowOther.Caption = GetCaptionWithCount("Show Other ", "d.IsOther = True")
3743+
37173744
End Sub
37183745

37193746

@@ -3724,24 +3751,32 @@ End Sub
37243751
' Purpose : Provides caption with a count appended if non-zero.
37253752
'---------------------------------------------------------------------------------------
37263753
'
3727-
Private Function GetCaptionWithCount(TemplateCaption As String, CountSQL As String) As String
3754+
Private Function GetCaptionWithCount(TemplateCaption As String, CountFilter As String) As String
37283755
Dim rs As DAO.Recordset
3729-
Set rs = CodeDb.OpenRecordset(CountSQL, dbOpenSnapshot)
3756+
Set rs = CodeDb.OpenRecordset( _
3757+
"SELECT COUNT(d.TableName) FROM tblTableData AS d WHERE " & CountFilter, dbOpenSnapshot)
37303758
If rs.EOF = False Then
37313759
If Nz(rs.Fields(0).Value, 0) Then
37323760
GetCaptionWithCount = TemplateCaption & " (" & rs.Fields(0).Value & ")"
37333761
Exit Function
37343762
End If
37353763
End If
3736-
37373764
GetCaptionWithCount = TemplateCaption
37383765
End Function
37393766

37403767

3768+
'---------------------------------------------------------------------------------------
3769+
' Procedure : cmdOpenInstallFolder_Click
3770+
' Author : Adam Waller
3771+
' Date : 7/6/2023
3772+
' Purpose : Open the installation folder
3773+
'---------------------------------------------------------------------------------------
3774+
'
37413775
Private Sub cmdOpenInstallFolder_Click()
37423776
Application.FollowHyperlink modInstall.GetInstallSettings.strInstallFolder
37433777
End Sub
37443778

3779+
37453780
'---------------------------------------------------------------------------------------
37463781
' Procedure : cmdRestoreDefaults_Click
37473782
' Author : Adam Waller
@@ -3883,7 +3918,7 @@ Private Sub MapControlsToOptions(eAction As eMapAction)
38833918
Dim pge As Access.Page
38843919
Dim ctl As Access.Control
38853920
Dim strKey As String
3886-
Dim dSettings As Scripting.Dictionary
3921+
Dim dSettings As Dictionary
38873922

38883923
' Loop through each page
38893924
For Each pge In tabOptions.Pages
@@ -4024,6 +4059,7 @@ Private Sub txtExportFolder_BeforeUpdate(Cancel As Integer)
40244059

40254060
End Sub
40264061

4062+
40274063
'---------------------------------------------------------------------------------------
40284064
' Procedure : GetTableIcon
40294065
' Author : Adam Waller & Indigo744
@@ -4049,7 +4085,7 @@ Private Function GetTableIcon(ByRef lngColumn As eTableCol) As String
40494085
' http://www.fileformat.info/info/unicode/char/21aa/index.htm
40504086
GetTableIcon = ChrW$(8618)
40514087
Case Else
4052-
' Everything else are linked table
4088+
' Anything else would be a linked table
40534089
' Uses symbol EARTH GLOBE AMERICAS
40544090
' https://www.fileformat.info/info/unicode/char/1f30e/index.htm
40554091
GetTableIcon = ChrW$(55356) & ChrW$(57102)

Version Control.accda.src/forms/frmVCSTableData.bas

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Begin Form
1616
Width =5040
1717
DatasheetFontHeight =11
1818
ItemSuffix =49
19-
Left =1125
20-
Top =2910
21-
Right =6945
22-
Bottom =5940
19+
Left =2115
20+
Top =2610
21+
Right =8205
22+
Bottom =5895
2323
RecSrcDt = Begin
2424
0xb0f4ef174201e640
2525
End
@@ -111,7 +111,7 @@ Begin Form
111111
Top =900
112112
Width =2625
113113
Height =360
114-
ColumnWidth =4545
114+
ColumnWidth =3510
115115
ColumnOrder =1
116116
TabIndex =1
117117
LeftMargin =44

Version Control.accda.src/modules/modFunctions.bas

+12
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,18 @@ Public Function IsEmptyArray(varArray As Variant) As Boolean
777777
End Function
778778

779779

780+
'---------------------------------------------------------------------------------------
781+
' Procedure : BitSet
782+
' Author : Adam Waller
783+
' Date : 5/19/2020
784+
' Purpose : Returns true if the flag is set.
785+
'---------------------------------------------------------------------------------------
786+
'
787+
Public Function BitSet(lngFlags As Long, lngValue As Long) As Boolean
788+
BitSet = CBool((lngFlags And lngValue) = lngValue)
789+
End Function
790+
791+
780792
'---------------------------------------------------------------------------------------
781793
' Procedure : Repeat
782794
' Author : Adam Waller

0 commit comments

Comments
 (0)