Access OOP examples wanted (2 Viewers)

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:31
Joined
Feb 28, 2001
Messages
26,999
I'm going to toss out a suggestion, to be acted on after a chance for folks to look at it and think about it. It might be a good idea to move MajP's examples into the forum's examples library under a sub-heading of "OOP usage and implementation." Just a thought. Since I'm not a moderator, I can't do it and I am not sure how the rest of the senior members feel about such things. But MajP, it is a nice contribution. Thanks.
 

moke123

AWF VIP
Local time
Today, 13:31
Joined
Jan 11, 2013
Messages
3,852
Not sure how I missed this thread as I've been searching extensively for the past week on classes and withevents.
I'm gonna blame it on Jon and the fact the site has been behaving badly.

Thanks,
Some People
 

jdraw

Super Moderator
Staff member
Local time
Today, 13:31
Joined
Jan 23, 2006
Messages
15,364
Doc,

I agree with your idea of making a subheading/group re "OOP usage and implementation".
I have added to this thread and referenced it over the last few years with links to class module articles and examples. Several others have commented and offered examples or links as well.
Because there has been so little info and examples re class module usage and OOP with Access (youtube and internet generally), I think it would be a great service to have such a grouping in the forum's library area.
MajP seems to be very familiar with OOP and open to sharing his code and examples for which I am appreciative.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 17:31
Joined
Feb 19, 2013
Messages
16,553
I agree would be a good idea. OOP is a different world and takes some getting used to (like moving from excel thinking to db thinking) so real world examples are always worthwhile.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:31
Joined
May 21, 2018
Messages
8,463
For clarity this thread is really talking about developing Custom Classes and not OOP in general. I think people fail to understand when working in Access VBA that almost every application uses extensive OOP. Anytime you are working with any object you are doing OOP. Any form, any control, recordset, collection, tabledef, etc. Everytime you use the word Set, build an event procedure, or reference a property your doing OOP. Everytime you are working with a form or report code you are doing OOP. VBA does not provide all the tenets/functionality of most object oriented languages, but if you are working with objects in VBA it is still OOP. So most vba developers are well versed in OOP by working with objects, just not versed in building their own classes.

What is good about developing and using custom classes, it gives you a better understanding of the native classes and how they work and how they can be used. A form or report class is no different in useage from a custom class. Building custom classes allows you to encapsulate a lot of functionality and hide the internal workings from the user. Although I use custom classes extensively, the most used classes I develop are like the examples posted. I take a control, form, or groups of these and basically wrap them in a class. Then you can extend the capability of these controls and groups. You can make them act as if they work together. When building custom classes the idea is to build a black box that is easily reuseable. Sometimes I will post a class to performa a function, and the response may be "you do not need to do build a class that is to complicated, you could write this code...". The comment does really make sense, because I did not write the class to solve the OPs issue. I wrote it a long time ago to solve any OP's same issue. I just imported them into an application from my library. So for example the Find as You Type combobox turns any combo box into a Find/Filter as you type. It requires one line of code to initialize. It reacts to many of the combo's events and form events, but that is transparent to the user. Yes you could write standard code to do this but each time you use it will require lots of modification of code and would be very hard to encapsulate this and make it easily reusable.

I do not know the inner workings of the native Collection class but I do know how to use a Collection to add, delete, reference, and count items. Same with working with someone elses custom classes. You just need to figure out how to use it and not how it was built.

I have seen on this thread questions of "what is the value of OOP?" Again I assume they mean "what is the value of custom classes?" because you are always doing OOP in Access VBA. Custom classes are not always the solution but can make very complex things easier and more understandable. Can make things far easier to use and more reuseable. Can wrap a lot of functionality up into a "black box" and extend the functionality of other objects.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 13:31
Joined
Apr 27, 2015
Messages
6,286
Some people have shown interest in custom classes lately, and was asked for some more examples. I use custom classes extensively, but the most important use in Access is the ability to extend control functionality and basically simulate building a user control. Once you build it once you can encapsulate a tremendous amount of functionality and reuse it without having to rewrite code. Normally it requires one or two lines to initialize the class. Here are a few examples

1) Find/Filter as you Type (FAYT). There are several classes here that turn a combobox, form, or listbox into a find as you type. In other words as you type it filters the list. There are several properties to configure how it filters

2) Listbox sorter. This captures the events of several command buttons and the listbox to allow the user to move records up and down in the list. It has lots of features to return the sorted list or row / column values.

3) From To List. Allows you to take any two listboxes and a group of command buttons and move items from one list to the other list.

4)MultiSelect Listbox control. This takes a multiselect listbox and returns a filter string based on the bound column

OutSTANDING post, thanks for the examples! I was just researching a way to sort a list box and was VERY close to resorting to a temp table...
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 13:31
Joined
Apr 27, 2015
Messages
6,286
I'm going to toss out a suggestion, to be acted on after a chance for folks to look at it and think about it. It might be a good idea to move MajP's examples into the forum's examples library under a sub-heading of "OOP usage and implementation." Just a thought. Since I'm not a moderator, I can't do it and I am not sure how the rest of the senior members feel about such things. But MajP, it is a nice contribution. Thanks.

Concur, to the highest level of concurtivity
 

isladogs

MVP / VIP
Local time
Today, 17:31
Joined
Jan 14, 2017
Messages
18,186
I'm more than happy to move MajP's examples to Sample Databases or Code Samples if he wants me to do so.

However mods aren't able to create new subforums so I can't create a separate area. Only Jon and possibly Vassago can alter the forum structure.
In any case, I'm not sure that creating further subforums is necessarily a good idea and if we are about to change to Xenforo, perhaps now isn't the time to do that anyway.

@MajP
Please let me know if you want me to move your post with the four examples and if so, which forum to move them to. I haven't had time to look at any of them so would appreciate your response. Thanks
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:31
Joined
May 21, 2018
Messages
8,463
@MajP
Please let me know if you want me to move your post with the four examples and if so, which forum to move them to. I haven't had time to look at any of them so would appreciate your response.

Moving to the code repository would be fine. Please title
"Developing Custom Classes to Simulate User Controls"

These examples all simulate making a User Control. For those who do not program in other applications you can build your own user controls and reuse them like any other control.
A user control is basically a grouping of other existing control, intended as a reusable component (i.e. composite control).
 

isladogs

MVP / VIP
Local time
Today, 17:31
Joined
Jan 14, 2017
Messages
18,186
MajP

Hmmm. Not as easy as I thought.
Whilst its easy to move an entire thread (which isn't appropriate here), there seems to be no obvious way I can move or copy just one post. :banghead:

So, please can you post a thread in the repository with that title and any extra text. I will then COPY the rest of the text, plus attachments from post #60 & then approve it. Alternatively, please feel free to copy all the text & attachments yourself so I just need to approve it

I'll then also paste a link in this thread

If you can report your post when you do so, I'll get a notification and follow up fairly promptly. Thanks

If you need to do any further editing to that thread after it is approved, you will of course be able to do so
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:31
Joined
May 21, 2018
Messages
8,463
I will just post to the Code repository, and I can reference the link once approved.
 

deletedT

Guest
Local time
Today, 17:31
Joined
Feb 2, 2019
Messages
1,218
Some people have shown interest in custom classes lately, and was asked for some more examples. I use custom classes extensively, but the most important use in Access is the ability to extend control functionality and basically simulate building a user control. Once you build it once you can encapsulate a tremendous amount of functionality and reuse it without having to rewrite code. Normally it requires one or two lines to initialize the class. Here are a few examples

1) Find/Filter as you Type (FAYT). There are several classes here that turn a combobox, form, or listbox into a find as you type. In other words as you type it filters the list. There are several properties to configure how it filters

2) Listbox sorter. This captures the events of several command buttons and the listbox to allow the user to move records up and down in the list. It has lots of features to return the sorted list or row / column values.

3) From To List. Allows you to take any two listboxes and a group of command buttons and move items from one list to the other list.

4)MultiSelect Listbox control. This takes a multiselect listbox and returns a filter string based on the bound column

@MajP, the last two databases doesn't contain class modules.
Or am I missing something?

I don't know commenting in code repository forum is allowed or not. So I posted here.
I couldn't find any class in following files:

FromToList Generic SingleSelect v3.accdb
MultiSelectListBoxQuery v2.accdb

And what does the number of views in front of each file means?
thank you.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:31
Joined
May 21, 2018
Messages
8,463
Tera, thanks for the catch. The last db was not the correct db, I need to post the correct db. Not even sure if that was my code. I deleted it from here and will add back.

The second to last From To List is a real important example, and it needs a lot better explanation. As I have discussed a form is a class and follows the same use as a custom class. In this example I use the form FromToList in multiple forms as a subform acting as a control. I have put in the form multiple custom events, custom properties, and methods. It is able to act as a control on multiple forms because the properties are passed into it. If you look how this subform is used and the subform's class this will look almost identical to using a custom class. If you can wrap your head around this useage you will have a real good understanding of OOP in Access.

I originally made this as a custom class where you could provide the listboxes and command buttons. So I will go back and update this module with both versions. A pure custom class and a customized form class. That would highlight even more concepts.

And what does the number of views in front of each file means?
thank you
Those are downloads.
 

deletedT

Guest
Local time
Today, 17:31
Joined
Feb 2, 2019
Messages
1,218
The second to last From To List is a real important example, and it needs a lot better explanation. As I have discussed a form is a class and follows the same use as a custom class. In this example I use the form FromToList in multiple forms as a subform acting as a control. I have put in the form multiple custom events, custom properties, and methods. It is able to act as a control on multiple forms because the properties are passed into it. If you look how this subform is used and the subform's class this will look almost identical to using a custom class.

I think I found something new to learn. I promise to stay away from movies this weekend and work on it. I had planned to watch Witness for the Prosecution. But your database seems to be much more thrilling.

Be prepared for a lot of nonsense questions please.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:31
Joined
May 21, 2018
Messages
8,463
I updated the MultiSelectListBoxControl with the correct file in this thread. In the code repository it needs to get approved. Thanks for the catch.
 

moke123

AWF VIP
Local time
Today, 13:31
Joined
Jan 11, 2013
Messages
3,852
I think I found something new to learn. I promise to stay away from movies this weekend and work on it. I had planned to watch Witness for the Prosecution. But your database seems to be much more thrilling.

Be prepared for a lot of nonsense questions please.

I feel your pain Tera. I've been at it for @2weeks straight since MajP posted an example that finally made sense to me. Its hard but I feel like i'm making progress.
 

Users who are viewing this thread

Top Bottom