Adding a form to a table

I

imtelling

I have a database of all our current members, and need to somehow add a form
that will allow me to pull up family information (i.e. children's
names/bdays/etc) for each member when I click on that member's name. How do I
go about doing this?
 
D

Duane Hookom

You create a table of relatives with fields for the information as required.
You need to have a field that links to the primary key of the member table.

Then you create a form that displays the relatives table in the desired
format. After that, go back to the design of your member form and use the
command button wizard to add a button to open the form with a filter for the
current member.

I would probably consider adding a subform (maybe on a tab control) to the
member form. This would be the easiest.
 
K

Ken Sheridan

You'll have table Members say, with one line per member. This should have a
unique numeric column, MemberID say, as its primary key, as names can be
duplicated, as well as columns such as FirstName, LastName etc. Create a
form, in single form view, bound to this table, or better still to a query
which sorts the members by LastName so they are presented alphabetically on
the form. You can use the form wizard to create the form or design it
yourself.

To find a member add an unbound combo box to the form header set up as
follows:

RowSource: SELECT [MemberID], [FirstName] & " " & [LastName] FROM
[Members] ORDER BY [LastName], [FirstName];

BoundColum: 1
ColumnCount: 2
ColumnWidths: 0cm;8cm

If your units of measurement are imperial rather than metric Access will
automatically convert the last one. The important thing is that the first
dimension is zero to hide the first column and that the second is at least as
wide as the combo box.

In the AfterUpdate event procedure of the combo box put the following code:

Dim rst As Object
Dim ctrl As Control

Set rst = Me.Recordset.Clone
Set ctrl = Me.ActiveControl

With rst
.FindFirst "[MemberID] = " & ctrl
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With

By selecting a member in the combo box the form will move to that record.

When it comes to family membership it depends how you've stored that data as
there are several ways you might have approached this:

1. If you've used a separate table, FamilyMembers say, with a foreign key
column MemberID referencing the primary key of members and other columns such
as FirstName, LastName, DoB, Relationship etc. (the last for husband, wife,
son, daughter etc) then you can create a continuous view subform based on
this table and embed it as a subform in the main members form, linking the
parent form and subform on MemberID by setting this as the subform control's
LinkMasterFields and LinkChildFields properties.

2. An alternative model you might have used is to include everybody in the
one Members table and to relate this to itself by a second FamilyMembership
table with columns MemberID and FamilyMemberID and Relationship (this time
the latter will include a value Self as well as husband, wife etc). With
this model the main form would be based on a query which joins the two tables:

SELECT [Members].*
FROM [Members] INNER JOIN [FamilyMembership]
ON [Members].[MemberID] = [FamilyMembership].[MemberID]
WHERE [Relationship] = "Self"
ORDER BY [LastName], [Firstname];

and the subform on a query such as:

SELECT [FamilyMembership].[MemberID], [FirstName], [LastName], [DoB]
FROM [Members] INNER JOIN [FamilyMembership]
ON [Members].[MemberID] = [FamilyMembership].[FamilyMemberID]
WHERE [Relationship] <> "Self"
ORDER BY [LastName], [Firstname];

Note that in this query you need to return the MemberID from the
FamilyMembership table and the names etc from the Members table. You only
need to qualify the meberID with the table name as this is the only column
which exists in both tables.

The parent and subforms would be linked in the same way as with 1. Note
that even if a member has no family they must still have a row in
FamilyMembership joining the member to themself by having the same value in
the MemberID and FamilyMemberID columns and 'Self' in the Relationship column.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top