473,750 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Class Modules for One-Many Relationship

I'm just learning how to use class modules in Access (2000 or XP). So far,
I've created two classes, with the data manipulation for the corresponding
tables encapsulated inside each of them

Member
Membership

The problem is that one Member can have many Memberships, and I'm having a
problem figuring out how to relate them. Ideally I'd like my calling code
to be able to say:
Member.Membersh ips(x).Update
or something like that. There are also cases where I need to update all of
a Member's memberships at once (as in the case of a death, for instance),
and I was thinking I could set up up to say
Member.Membersh ips.UpdateAll
or similar.

I'm getting the impression that in order to make that work, I need a class
called Memberships in the middle, with a collection. Is that correct? Can
someone provide me with some pointers on what code I need, or at least some
reading material which will help me wrap my head around this?

Thanks in advance.

Shannon Rotz
Vancouver, BC Canada
Nov 13 '05 #1
3 1846
rkc

"Shannon Rotz" <sr***@shaw.c a> wrote in message
news:3o%3d.4848 31$gE.32370@pd7 tw3no...
I'm just learning how to use class modules in Access (2000 or XP). So far, I've created two classes, with the data manipulation for the corresponding
tables encapsulated inside each of them

Member
Membership

The problem is that one Member can have many Memberships, and I'm having a
problem figuring out how to relate them. Ideally I'd like my calling code
to be able to say:
Member.Membersh ips(x).Update
or something like that. There are also cases where I need to update all of a Member's memberships at once (as in the case of a death, for instance),
and I was thinking I could set up up to say
Member.Membersh ips.UpdateAll
or similar.

I'm getting the impression that in order to make that work, I need a class
called Memberships in the middle, with a collection. Is that correct? Can someone provide me with some pointers on what code I need, or at least some reading material which will help me wrap my head around this?


My guess is that what you need is a vba.collection as a part of your
Member class that holds a collection of Membership classes.

Or,

Depending on the makeup of your Membership class, you may
only need an array that holds the primary keys of the Membership
records related to each member.


Nov 13 '05 #2
Well, you can't use the class objects to "build" the relationships for you.

A class object is just a "bunch" of code stuck together, and makes it easer
to code with. So, it don't really help much in terms of a relationship
between a master and child table.

However, you can certainly make a class object that lets you "manipulate " a
member.

dim MyMember as new clsMemberShip
MyMember.Member ID = 123

MyMember.SetAll MembershipsStat us = "InActive"

So, the above code would load a membership person with key id of 123.

Then, to update all the memberships to status to inactive, then you could
use the 2nd line of code.

However, the code in the class object will simply be a bunch of sql
statements, or code that updates the child records.

It is not clear in your example what you mean by "x" in:
Member.Membersh ips(x).Update


I mean, you have to identify each child record some how...likely the key id
field of the child records is the best to use here? It is not the fact that
you want to use "x", but how did x get set to what is the issue here? What,
when, how did "x" get set to select what child record (memberships) to work
on is the issue here.

MyMember.Member ID = 123
MyMember.Member ShipID = 1388
MyMember.Member ShipStats = "Active"

In the above example, I set the Membership status to Active for the
membership record with a key id of 1388.
The code for the property MemberShipID would look like:

Public Property LET (lngMemberShipI D as long)

m_MemberShipID = lngMemberShipID

end Propeirty
The code behind the MembershipStatu s method could look like:

Public Property LET (strStatus as string)

dim sql as string

sql = "update tblMemberships set Status = '" & strStatus & "' where ID =
" & m_MembershipID
currentdb.Execu te sql
end Property

I can't really say that using a class object JUST to work with a one to many
relationship is much help. You can't use class objects in sql, or really
very much in a report. However, a class object certainly can be handy if you
have a LOT of code you are writing that must manipulate, or change the
status of a membership records. If you don't have a lot of code you are
writing to update the membership stuff, then the class object don't help
much.

You can read about "when" and "when not" to use a class object here:

I also give some example usages.
http://www.attcanada.net/%7ekallal.m.../WhyClass.html

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #3
"Albert D. Kallal" <Pl************ *******@msn.com > wrote in
news:zi14d.4673 80$M95.299290@p d7tw1no:

A class object is just a "bunch" of code stuck together, and makes it
easer to code with.


Oh!

--
Lyle
--
use iso date format: yyyy-mm-dd
http://www.w3.org/QA/Tips/iso-date
--
The e-mail address isn't, but you could use it to find one.
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1511
by: Tobias Pfeiffer | last post by:
Hi! I want to write a package of modules that deal with mathematical graphs. So my plan is to have a main.py file where the basic operations are done, like reading the file and creating an adjacence list and all that. In this main.py file, there is created a Graph class with several methods, such as deg(v) or delvertex(v). And then, for all of the other things one can do with a graph, I want to code other modules, e.g. a file euler.py...
3
3411
by: mehul | last post by:
Hi, I am trying to use Active Reports v1.1 (Build 1.1.0.84) in a ASP.NET application. Is it possible to use it through the COM interlop as Crystal Reports for .NET which comes built in with VS.NET doesnt work properly. Rgs,
13
2221
by: Bijoy Naick | last post by:
My project contains multiple aspx pages. Many of these pages have code-behind that use several helper functions. Instead of copying each helper function into each aspx page, I am thinking of using a VB Class file to store these. Questions - - How would I "include" this class in each aspx page?
3
1878
by: Phillip Ian | last post by:
Just a quick architecture question. I'm just looking for discussion, not a flame war, please. In the past, I've tended to use a public module for my data layer functions. Something like: public module db Friend ConnectionString As String = "" Public Sub InitializeDB(ByVal AConnectionString As String)
10
5494
by: Bonzol | last post by:
vb.net Hey there, could someone just tell me what the differnce is between classes and modules and when each one would be used compared to the other? Any help would be great Thanx in advance
45
2720
by: Luvin lunch | last post by:
Hi, I'm new to Access and have been asked to develop a simple Access system to replace one that already exists. There are five users of the current Access system and each of the users works off a copy of the system on their local machines. I would like to develop my new system as a multi-user system and place it on a server to be accessed remotely by each of the users. I have read that the locking in MS Access can be hellish. Most...
0
1210
by: nandar | last post by:
Hi All, I am involved in migratinig one of the MS Access Project to ASP.Net and SQL Server 2000. My question here is that how Modules and Class Modules (MS Access) can be taken care in ASP.Net. To some extend I know the answer (I beleive) but I want to know whether that is the right way or any other solution is available. My understanding is, 1) MS Access Modules will be placed in the App_code directory (wrt .Net 2.0) and set the Methods...
13
2697
by: André | last post by:
Hi, i'm developping asp.net applications and therefore i use VB.net. I have some questions about best practises. According what i read about class and module and if i understand it right, a module does the same as a class but cannot herite or be herited. 1)Is that right? 2) So i guess this module does exactly the same as the class?
1
2620
osward
by: osward | last post by:
Hi everyone, Background 1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >= current date. Otherwise, user have to waste time to page up the pages to find the current date 2. I got a script of simple calendar from the web that use mktime() to create links on the calendar Task I need to let user view data earlier than...
18
2294
by: Angus | last post by:
Hello We have a lot of C++ code. And we need to now create a library which can be used from C and C++. Given that we have a lot of C++ code using classes how can we 'hide' the fact that it is C++ from C compilers? Can we have a C header file which uses the functionality of the C++ files and compile this into a lib file?
0
8999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9338
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4712
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.