Color scheme: Dark
You are here: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library API reference » WklRibbon

WklRibbon

WklRibbon class

Signature

Dim myWklRibbon As New WklRibbon

Summary

Makes the ribbons, the File view and the context menus of a database from one model of commands, and runs them: the conditions under which an element shows, values set by code, and the actions.

Parameters

None

Remarks

WklRibbon is an object, not a control. It has three uses:

  • Designer and store. ShowDesigner opens the ribbon designer for the current database (also from the add-in menu Database Tools › Add-Ins › WKL Ribbon Designer). Save writes a model into the current database: the model into the table USysWklRibbon, each ribbon's RibbonXML into USysRibbons, the application ribbon into the database property CustomRibbonID, and the callbacks into the module basWklRibbon. Access shows a changed ribbon after the database was closed and opened again, as for ribbons written by hand.
  • Generator. Check, Canonical, RibbonNames, RibbonXml and ModuleText work on a model text without Access; the build tool uses them (ribbonModel in access-app.json).
  • Runtime. The generated module basWklRibbon passes every ribbon callback to a WklRibbon object through hidden members, which are not for application code: it answers labels, visibility and readiness, and runs the action of a command. Code gets the same object with WklRibbonObject(), a function of the module, to set values (Visible, Enabled, Label, Pressed), ask again (Invalidate) or listen to Action.

The state of the ribbons belongs to the database in the Access session, not to one object: a new object finds it again, also after a project reset (an unhandled error, End). Conditions: a command, tab, group or tab of the File view shows when the connection profile (the one set with Profile, else the one most linked tables use, as WklLinkManager.DetectEnvironment), the kind of database (ACCDB, ACCDE, runtime) and a function of the application (returning True) all agree. Hiding is a convenience, not a protection: whoever can open the database can run the action anyway, so the check belongs into the data source.

Callbacks never fail towards Access: when the runtime cannot answer, an element stays hidden, and a failing action raises ActionError instead of a message box. A function named as action should handle its own errors: an unhandled error in it shows the VBA error dialog, as for every function a ribbon calls.

Created with New WklRibbon or CreateObject.

MemberKindSummary
`Check`MethodChecks a model and returns its problems.
`Canonical`MethodReturns a model in its fixed text form.
`RibbonNames`MethodReturns the names of the ribbons of a model.
`RibbonXml`MethodReturns the RibbonXML of one ribbon of a model.
`ModuleText`MethodReturns the text of the callback module basWklRibbon for a model.
`Load`MethodReturns the model of the current database.
`Save`MethodSaves a model in the current database.
`ShowDesigner`MethodOpens the ribbon designer for the current database.
`Invalidate`MethodAsks every loaded ribbon again for labels, visibility and readiness, and makes the context menus again.
`InvalidateCommand`MethodAsks the elements of one command again.
`Visible`PropertyGets or sets whether a command is visible.
`Enabled`PropertyGets or sets whether a command can be run (default True).
`Label`PropertyGets or sets the label of a command.
`Pressed`PropertyGets or sets the state of a toggle button.
`ResetCommand`MethodRemoves visibility, readiness and label set by code for a command.
`Profile`PropertyGets or sets the connection profile the conditions use.
`ActivateTab`MethodShows a tab of a loaded ribbon.
`Execute`MethodRuns a command as if the user had chosen it: Action, then the action of the model.
`EnsureMenus`MethodMakes the context menus of the saved model as temporary command bars of this Access session, so a form, report or control naming one in Shortcut Menu Bar (ShortcutMenuBar) shows it.
`ApplyAssignments`MethodWrites the context menu assignments of the saved model into the forms and reports of the current database: Shortcut Menu Bar of the form or report itself, of a named control, or of every control of a kind.
`ShowAssignments`MethodOpens the ribbon designer on the page Assignments: which form, report, control or kind of control shows which context menu of the model. The add-in menu entry Database Tools › Add-Ins › WKL Shortcut Menu Designer calls it.
EventSummary
`Action`Occurs when the user chooses a command: a button, a menu entry, a task of the File view, a context menu entry, or Execute.
`ActionError`Occurs when the action of a command failed: the form or report does not exist, or the function is missing or raised an error Access reports to the caller. No message box is shown.

Code example

' In the module of the start form: the ribbon follows the signed-in user.
Private WithEvents mRibbon As WklRibbon
 
Private Sub Form_Load()
    Set mRibbon = WklRibbonObject()
    mRibbon.Enabled("cmdExport") = Nz(TempVars("darfExportieren"), False)
End Sub
 
Private Sub mRibbon_Action(ByVal Command As String, ByVal Pressed As Boolean, Cancel As Integer)
    If Command = "cmdDelete" And Me.Dirty Then Cancel = True
End Sub

Inheritance

None

Check method

Signature

Function Check(ByVal Model As String) As String

Summary

Checks a model and returns its problems.

Parameters

NameTypeOptionalDefaultDescription
ModelStringNo–The model text (JSON).

Return value: String – One problem per line, in the language of the components; empty when the model can be saved. A text that is no model gives its error as the only line; Check never raises an error.

Remarks

None

Code example

None

Inheritance

Declared by WklRibbon.

Canonical method

Signature

Function Canonical(ByVal Model As String) As String

Summary

Returns a model in its fixed text form.

Parameters

NameTypeOptionalDefaultDescription
ModelStringNo–The model text.

Return value: String – The text the database keeps and the build tool exports: keys in fixed order, defaults left out, two spaces indentation, LF line ends.

Remarks

A text that is no model raises wkeInvalidValue. The canonical text of a canonical text is the same, byte for byte.

Code example

None

Inheritance

Declared by WklRibbon.

RibbonNames method

Signature

Function RibbonNames(ByVal Model As String) As String

Summary

Returns the names of the ribbons of a model.

Parameters

NameTypeOptionalDefaultDescription
ModelStringNo–The model text.

Return value: String – The names separated by semicolons, in the order of the model.

Remarks

None

Code example

None

Inheritance

Declared by WklRibbon.

RibbonXml method

Signature

Function RibbonXml(ByVal Model As String, ByVal Name As String) As String

Summary

Returns the RibbonXML of one ribbon of a model.

Parameters

NameTypeOptionalDefaultDescription
ModelStringNo–The model text.
NameStringNo–The ribbon's name.

Return value: String – The XML for the column RibbonXML of USysRibbons.

Remarks

A model with problems raises wkeInvalidValue with the first problem; an unknown name raises wkeKeyNotFound.

Code example

None

Inheritance

Declared by WklRibbon.

ModuleText method

Signature

Function ModuleText(ByVal Model As String) As String

Summary

Returns the text of the callback module basWklRibbon for a model.

Parameters

NameTypeOptionalDefaultDescription
ModelStringNo–The model text.

Return value: String – The module with its Attribute VB_Name line, as LoadFromText reads it.

Remarks

None

Code example

None

Inheritance

Declared by WklRibbon.

Load method

Signature

Function Load() As String

Summary

Returns the model of the current database.

Parameters

None

Return value: String – The model text from USysWklRibbon; empty when the database has none.

Remarks

Needs an Access database open in this process; elsewhere it raises wkeNotConfigured.

Code example

None

Inheritance

Declared by WklRibbon.

Save method

Signature

Sub Save(ByVal Model As String, Optional ByVal WriteModule As Boolean = True)

Summary

Saves a model in the current database.

Parameters

NameTypeOptionalDefaultDescription
ModelStringNo–The model text.
WriteModuleBooleanYesTrueTrue (default) writes the module basWklRibbon too; False leaves it out (the build tool loads it itself).

Remarks

The model, the ribbons and CustomRibbonID are written at once; the module follows once the VBA procedure that called Save has ended, because Access replaces no module while VBA runs. Only the rows of USysRibbons that belong to the model (now or before) are replaced; other ribbons stay. A model with problems raises wkeInvalidValue; a refused write raises wkeSourceError.

Code example

None

Inheritance

Declared by WklRibbon.

ShowDesigner method

Signature

Function ShowDesigner() As Boolean

Summary

Opens the ribbon designer for the current database.

Parameters

None

Return value: Boolean – True when it was closed with OK (the model is saved then).

Remarks

After OK the context menu assignments of the page Assignments are written into the forms and reports (see ApplyAssignments). Forms and reports that are open are left alone; a message names them.

Code example

None

Inheritance

Declared by WklRibbon.

Invalidate method

Signature

Sub Invalidate()

Summary

Asks every loaded ribbon again for labels, visibility and readiness, and makes the context menus again.

Parameters

None

Remarks

Needed after a change the runtime cannot see, for example when the function named in a condition would now answer differently. Values set through Visible, Enabled, Label and Pressed take effect without it.

Code example

None

Inheritance

Declared by WklRibbon.

InvalidateCommand method

Signature

Sub InvalidateCommand(ByVal Command As String)

Summary

Asks the elements of one command again.

Parameters

NameTypeOptionalDefaultDescription
CommandStringNo–The command's name in the model.

Remarks

An unknown command raises wkeKeyNotFound.

Code example

None

Inheritance

Declared by WklRibbon.

Visible property

Signature

Property Get Visible(ByVal Command As String) As Boolean
Property Let Visible(ByVal Command As String, RHS As Boolean)

Summary

Gets or sets whether a command is visible.

Parameters

NameTypeOptionalDefaultDescription
CommandStringNo–The command's name.

Property value: Boolean – Setting False hides the command wherever it stands; True shows it where its condition holds. Gets the effective visibility.

Remarks

The value applies in addition to the condition: it can hide a command, not show one its condition hides. ResetCommand removes it.

Read/write.

Code example

None

Inheritance

Declared by WklRibbon.

Enabled property

Signature

Property Get Enabled(ByVal Command As String) As Boolean
Property Let Enabled(ByVal Command As String, RHS As Boolean)

Summary

Gets or sets whether a command can be run (default True).

Parameters

NameTypeOptionalDefaultDescription
CommandStringNo–The command's name.

Property value: Boolean – False grays the command out in the ribbon, the File view and the context menus.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklRibbon.

Label property

Signature

Property Get Label(ByVal Command As String) As String
Property Let Label(ByVal Command As String, RHS As String)

Summary

Gets or sets the label of a command.

Parameters

NameTypeOptionalDefaultDescription
CommandStringNo–The command's name.

Property value: String – The text shown; set, it replaces the label of the model until ResetCommand.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklRibbon.

Pressed property

Signature

Property Get Pressed(ByVal Command As String) As Boolean
Property Let Pressed(ByVal Command As String, RHS As Boolean)

Summary

Gets or sets the state of a toggle button.

Parameters

NameTypeOptionalDefaultDescription
CommandStringNo–The command's name.

Property value: Boolean – True when pressed.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklRibbon.

ResetCommand method

Signature

Sub ResetCommand(ByVal Command As String)

Summary

Removes visibility, readiness and label set by code for a command.

Parameters

NameTypeOptionalDefaultDescription
CommandStringNo–The command's name.

Remarks

None

Code example

None

Inheritance

Declared by WklRibbon.

Profile property

Signature

Property Get Profile() As String
Property Let Profile(RHS As String)

Summary

Gets or sets the connection profile the conditions use.

Parameters

None

Property value: String – For example DEV, TEST or PROD; empty for the profile most linked tables use (as WklLinkManager.DetectEnvironment, empty when the database has no link configuration).

Remarks

Setting it asks the ribbons again.

Read/write.

Code example

None

Inheritance

Declared by WklRibbon.

ActivateTab method

Signature

Sub ActivateTab(ByVal TabId As String)

Summary

Shows a tab of a loaded ribbon.

Parameters

NameTypeOptionalDefaultDescription
TabIdStringNo–The tab's name in the model.

Remarks

An unknown tab raises wkeKeyNotFound; a tab of a ribbon Access has not loaded raises wkeNotAvailable.

Code example

None

Inheritance

Declared by WklRibbon.

Execute method

Signature

Sub Execute(ByVal Command As String)

Summary

Runs a command as if the user had chosen it: Action, then the action of the model.

Parameters

NameTypeOptionalDefaultDescription
CommandStringNo–The command's name.

Remarks

None

Code example

None

Inheritance

Declared by WklRibbon.

EnsureMenus method

Signature

Function EnsureMenus() As Long

Summary

Makes the context menus of the saved model as temporary command bars of this Access session, so a form, report or control naming one in Shortcut Menu Bar (ShortcutMenuBar) shows it.

Parameters

None

Return value: Long – The number of context menus made.

Remarks

Access forgets temporary command bars when it closes, so an application without a ribbon of the model calls EnsureMenus once when it starts; when a ribbon of the model loads, its onLoad makes the menus itself. It works in ACCDB, ACCDE and runtime. Calling it again makes the menus again from the saved model.

Code example

None

Inheritance

Declared by WklRibbon.

ApplyAssignments method

Signature

Function ApplyAssignments() As String

Summary

Writes the context menu assignments of the saved model into the forms and reports of the current database: Shortcut Menu Bar of the form or report itself, of a named control, or of every control of a kind.

Parameters

None

Return value: String – The changes, one per line (frmCustomers.txtName: (none) -> ctxCustomer); empty when nothing had to change.

Remarks

  • Which assignment wins. An assignment naming a control wins over one for its kind of control. A menu of the model that is no longer assigned is removed from where the model had put it; a context menu the model does not know (made by the application itself) is never removed, only replaced where the model assigns another.
  • Design view. Forms and reports are opened hidden in design view and saved only when something changed. One that is open is left alone and named in the result (frmCustomers: open, skipped).
  • ACCDB only. An ACCDE has no design view: ApplyAssignments raises wkeNotAvailable there. Assign before making the ACCDE; the build tool does it after loading forms and reports.

Code example

None

Inheritance

Declared by WklRibbon.

ShowAssignments method

Signature

Function ShowAssignments() As Boolean

Summary

Opens the ribbon designer on the page Assignments: which form, report, control or kind of control shows which context menu of the model. The add-in menu entry Database Tools › Add-Ins › WKL Shortcut Menu Designer calls it.

Parameters

None

Return value: Boolean – True when it was closed with OK (the model is saved and the assignments written then).

Remarks

Behaves like ShowDesigner; only the first page differs.

Code example

None

Inheritance

Declared by WklRibbon.

Action event

Signature

Event Action(ByVal Command As String, ByVal Pressed As Boolean, ByRef Cancel As Integer)

Summary

Occurs when the user chooses a command: a button, a menu entry, a task of the File view, a context menu entry, or Execute.

Parameters

NameTypeOptionalDefaultDescription
CommandStringNo–The command's name.
PressedBooleanNo–The state of a toggle button; False for other commands.
CancelInteger (by reference)No–True leaves the action of the model out.

Remarks

Events reach VBA only through a WithEvents variable on module level of a form, report or class: Set mRibbon = WklRibbonObject().

In a form module: Private Sub <ControlName>_Action(...). Parameters passed by reference can be changed by the procedure.

Code example

None

Inheritance

Declared by WklRibbon.

ActionError event

Signature

Event ActionError(ByVal Command As String, ByVal Description As String)

Summary

Occurs when the action of a command failed: the form or report does not exist, or the function is missing or raised an error Access reports to the caller. No message box is shown.

Parameters

NameTypeOptionalDefaultDescription
CommandStringNo–The command's name.
DescriptionStringNo–Access's message.

Remarks

In a form module: Private Sub <ControlName>_ActionError(...). Parameters passed by reference can be changed by the procedure.

Code example

None

Inheritance

Declared by WklRibbon.

en/wiki/msaccess/comctl/api-reference/wklribbon.txt · Last modified: by Wolfgang van der Stille