ADD-in Leszynski benaming

De Leszynski benamings overeenkomst, ontwikkeld door Stan Leszynski, is heel populair bij MS Access ontwikkelaars. Het principe bestaat erin om de naam van objecten te laten vooraf gaan door een drie-letterige prefix die aanduidt over welk type van object het gaat. De prefix is in kleine letters en de begin letter (4de dus) van het object met een hoofdletter.

Het gebruik van de benamings overeenkomst heeft veel voordelen. De database wordt zodoende goed gedocumenteerd, bij het schrijven van VBA code weet men dat frmVerkopers gaat over het formulier die de verkopers weergeeft, dat txtIdentificatie over een tekstvak gaat met als databron Identificatie....enz.

Waar de Leszynski benamings overeenkomst toegepast wordt op alle MS Access objecten, tabellen, Queries....zal de hier besproken Add-Inn enkel de benamings overeenkomst automatisch instellen voor Access-controls (besturings elementen) zoals tekstvakken, combo's formulieren enz. Dit in functie van een andere Add-Inn die ik gemaakt heb en die de bedoeling heeft een zekere consistentie te realisren bij de opmaak van mijn toepassingen.

Werkwijze

  1. Start een nieuwe Access database.
  2. Zorg er voor dat de systeem en verdoken objecten zichtbaar zijn en importeer of creƫer de USysRegInfo tabel.
  3. Start de VBA-editor en maak een nieuwe module en schrijf de VBA-code.
  4. Voorzie in de USysRegInfo tabel de juiste data.
  5. Sluit de database en wijzig via Windows verkenner de extensie in .accda.
  6. Bewaar het .accda bestand in map van de Add-Inns

De VBA-code

'Label - lbl
            'Textbox - txt
            'Option Group - opg
            'Toggle Buttons - tgb
            'Option Buttons - opb
            'Combo Boxes - cbo
            'List Boxes - lst
            'Command Buttons - cmd
            'Images - img
            'Unbound Object Frame - uof
            'Bound Object Frame - bof
            'Page Break - pgb
            'Tab Controls - tab
            'Sub Forms - sbf
            'Sub Reports - sbr
            'Lines - lin
            'Rectangles - rct
            
Public Function f_av_Leszynski()
            
            Dim aobj As Access.AccessObject
            Dim ctl As Access.Control
            
            On Error GoTo Foutbehandeling
                For Each aobj In CurrentProject.AllForms
                        DoCmd.OpenForm aobj.Name, acDesign
                            For Each ctl In Forms(aobj.Name)
                                If ctl.ControlType = acLabel Then
                                    If Left(ctl.Name, 3) <> "lbl" Then
                                        ctl.Name = "lbl" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acTextBox Then
                                    If Left(ctl.Name, 3) <> "txt" Then
                                        ctl.Name = "txt" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acComboBox Then
                                    If Left(ctl.Name, 3) <> "cbo" Then
                                        ctl.Name = "cbo" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acListBox Then
                                    If Left(ctl.Name, 3) <> "lst" Then
                                        ctl.Name = "lst" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acCheckBox Then
                                    If Left(ctl.Name, 3) <> "chk" Then
                                        ctl.Name = "chk" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acCommandButton Then
                                    If Left(ctl.Name, 3) <> "cmd" Then
                                        ctl.Name = "cmd" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acOptionButton Then
                                    If Left(ctl.Name, 3) <> "opb" Then
                                        ctl.Name = "opb" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acOptionGroup Then
                                    If Left(ctl.Name, 3) <> "opg" Then
                                        ctl.Name = "opg" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acSubform Then
                                    If Left(ctl.Name, 3) <> "sbf" Then
                                        ctl.Name = "sbf" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acImage Then
                                    If Left(ctl.Name, 3) <> "img" Then
                                        ctl.Name = "img" & ctl.Name
                                    End If
                                End If
            
                                If ctl.ControlType = acTabCtl Then
                                    If Left(ctl.Name, 3) <> "tab" Then
                                        ctl.Name = "tab" & ctl.Name
                                    End If
                                End If
            
                            Next ctl
                        DoCmd.Close acForm, aobj.Name, acSaveYes
                Next aobj
            Verlaten:
            Exit Function
            Foutbehandeling:
                MsgBox "Fout in f_av_Leszynski ; Foutnummer : " & vbCrLf & "Omschrijving : " & Err.Description, vbCritical + vbOKOnly, "av_Leszynski"
                Resume Verlaten
            End Function
            

USysRegInfo tabel.

SubkeyTypeValNameValue
HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins\Leszynski Controls0
HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins\Leszynski Controls1Library|ACCDIR\AV_Leszynski.accda
HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins\Leszynski Controls1Expression=f_av_Leszynski()
Begin