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
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.
| Subkey | Type | ValName | Value |
| HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins\Leszynski Controls | 0 | ||
| HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins\Leszynski Controls | 1 | Library | |ACCDIR\AV_Leszynski.accda |
| HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins\Leszynski Controls | 1 | Expression | =f_av_Leszynski() |