Class Modules and Private Variables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I recieve the error message "Ambiuous name detected: mID" during compilation
of the following class module. If I comment the offensive line, then the next
module level "private" statement's will return the error message. I have read
the help topic for this error and I don't seem to need any of the fixes. What
am I doing wrong?

==simple class module coding====

Option Explicit

Private mID As Long 'local copy
Private mvarName As String 'local copy
Private mvarRed As Integer 'local copy
Private mvarBlue As Integer 'local copy
Private mvarGreen As Integer 'local copy

Public Property Let mID(vdata As Long)
mID = vdata
End Property
Public Property Get ID() As Long
ID = mID
End Property

Public Property Let mvarName(vdata As String)
mvarName = vdata
End Property
Public Property Get Name() As String
Name = mvarName
End Property

Public Property Let mvarRed(vdata As Integer)
mvarRed = vdata
End Property
Public Property Get Red() As Integer
Red = mvarRed
End Property

Public Property Let mvarBlue(vdata As Integer)
mvarBlue = vdata
End Property
Public Property Get Blue() As Integer
Blue = mvarBlue
End Property

Public Property Let mvarGreen(vdata As Integer)
mvarGreen = vdata
End Property
Public Property Get Green() As Integer
Green = mvarGreen
End Property

Public Sub GetRGBColor(anID As Long)
Me.ID = anID
Me.Name = Excel.WorksheetFunction.VLookup(anID, Colors, 2)
Me.Red = Excel.WorksheetFunction.VLookup(anID, Colors, 3)
Me.Blue = Excel.WorksheetFunction.VLookup(anID, Colors, 4)
Me.Green = Excel.WorksheetFunction.VLookup(anID, Colors, 5)
End Sub
 
You can't have a property and a variable named the same thing,
'mID' in your case. Change your Property Let statement to

Property Let ID (vdata As Long)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Thanks!

You're right of course. As usual, right after posting my message, I discover
my error. Should have had a clue when I commented all the module level
"Private" statments out and the "ID" property as well as the other properties
were "read only".
 
Back
Top