Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting my class modules to behave like access'

Status
Not open for further replies.

JoeSmoe55

Programmer
Aug 1, 2005
38
US
Hello,

I just was wondering if anyone could tell me how to get my class modules to act like access system object in regards to returning readonly items or defaulting to the value. here is an example -

when using a listitem if you specify

li.listsubitems.item(3) (it's value will be returned but it also returns an object because you can also use it like this: li.listsubitems.item(3).forecolor = blue)
It is the exact same when using the Forms object.

thanks,
Joe
 
Provide more details. But if I understand you right, you want to create Default properties like you have with defined objects. For example, a control or a field has a default "value" property so
msgbox textBox1
is really shorthand for
msgbox textBox1.value
or
msgbox myRecordset.fields("myFieldName")
is really shorthand for
msgbox myRecordset.fields.item("myFieldName").value

And as your example shows a "collection" has a default "item" property, but as you show you are forced to use the "item" property in user defined collections.
Forms(3) or Forms.items(3)
works but
listsubitems(3)
does not work

I may be wrong, but I do not think that you can define your own default properties and methods.

But you also said you want read only properties. If you have a "get" method without a "let" or "set" your property is read only. You should be able to create read only properites easily.
 
Thanks MajP,

You understood what I wanted correctly.Sorry if the explanation was unclear. The solution is simple but tedious. I am too lazy to go through every one of my classes, so I will be doing it the old way. Thanks for your help and expertise.

Joe
 
I'm just jumping in here and may have missed out on getting a response, but I just have to ask. Does Access VBA not support a constructor method? I see that default properties are another issue altogether, whereas it looks as though the Forms(3) = Forms.Items(3) is more of a constructor issue. Granted, I don't believe I've ever heard of a constructor being named something other than the class (i.e. Forms.Forms(3) = Forms(3)), but I digress. I'm just starting to try to refactor some of my Access apps to be object oriented, and I'm having a little difficulty switching from thinking in terms of PHP 5 to VBA. Thanks for the help!

Ryan
 


In VBA a Class can have a single Constructor and a single Destructor. The Constructor must be named Class_Initialize and the Destructor must be named Class_Terminate. They are called automatically when a Class object is instantiated and destroyed, respectively. You don‘t need to call these Methods; they are called automatically by VBA

Private Sub Class_Initialize()
MsgBox "Initialized!"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top