VBC09372 — Member already exists in an object module from which this object module derives
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
The code of a form declares something with the name of one of the form's controls.
Every control of a UserForm is a member of the form's class: a Public variable of the control's class, named after the control, which the code refers to
(Me.TextBox1, UserForm1.TextBox1) and handles the events of (TextBox1_Change). The form's designer declares it, and not the code. A variable, a
constant, a procedure or a Declare of the same name in the code would be a second member of that name, which a class cannot have.
The controls inside a Frame, and on the pages of a MultiPage, are members of the form too. The pages of a MultiPage are not: their names are free,
and a page is reached through its MultiPage (MultiPage1.Pages("Page1")).
MS-VBA reports the same error, with the same message (recorded in Excel).
How it is raised
| Situation | Example, for a form with a TextBox1 |
Resolution |
|---|---|---|
| A variable of the control's name. | Private TextBox1 As String |
Name the variable after what it holds: Private EnteredText As String. |
| A procedure of the control's name. | Private Sub TextBox1() |
Rename the procedure. To run code when the control changes, handle its event: Private Sub TextBox1_Change(). |
| A constant of the control's name. | Private Const TextBox1 = 1 |
Rename the constant. |
Renaming the control in the form's designer, instead of the code's member, resolves it too.
Notes
MS-VBA compiles a WithEvents variable of a control's name (Private WithEvents TextBox1 As MSForms.TextBox), which reads as though it declared a
variable of its own in place of the control, and does not: there is still only the control. RD-VBA reports it with this error, which is what it should
have been all along.
See also
⏮️ VBC09371 Array argument must be ByRef | ⏭️ VBC09373 Automation type not supported in Visual Basic
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca