pyaccesskit.forms.vba¶
pyaccesskit.forms.vba ¶
VBA snippets for event procedures and helpers that assemble form modules.
Vba
dataclass
¶
Vba(code: str)
The body of a VBA event procedure, e.g. Vba("DoCmd.Close acForm, Me.Name").
Indentation is normalized; write the body only (no Sub/End Sub).
EventBinding
dataclass
¶
EventBinding(
object_name: str,
property_name: str,
event: str,
body: Vba,
)
An event wired to an [Event Procedure].
Attributes:
| Name | Type | Description |
|---|---|---|
object_name |
str
|
|
property_name |
str
|
The Access event property, e.g. |
event |
str
|
The VBA event name, e.g. |
body |
Vba
|
The procedure body. |
is_vba_identifier ¶
is_vba_identifier(name: str) -> bool
Whether name can be used as-is in a VBA procedure name (cmdSave_Click).
event_procedure ¶
event_procedure(binding: EventBinding) -> str
Render Private Sub <object>_<event>() ... End Sub (CRLF line endings).
build_module ¶
build_module(
bindings: Sequence[EventBinding],
extra_code: str | None = None,
*,
option_explicit: bool = True,
) -> str
Assemble a complete class-module text for a form: options, event procedures, extra code.
split_declarations ¶
split_declarations(code: str) -> tuple[str, str]
Split VBA into its declarations section and its procedures (Option lines are dropped).
Everything before the first Sub/Function/Property is the declarations section; comments
directly above that procedure stay with it. A #If ... #End If block containing that procedure is
never split: it moves to the procedures as a whole.