Good way to populate junction table?

M

MikeB

Hi, If I have two tables, Players and Tournaments, and I want to
quickly add a large number of Players to a new Tournament, what is the
best design for the form to do this?

I'm thinking (hoping) it is as easy as showing all the players with a
check box next to their names and checking them off, but I can't think
how that translates "behind the scenes" into putting the TournamentID
and PlayerID into the junction table.

Thanks.
 
J

Jeff Boyce

Mike

A problem with the "checkbox per player" approach is that you'd need to
modify your form every time you changed the number of players.

Have you looked into using paired listboxes (take a look at the Access query
wizard for an example)?

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
M

MikeB

Jeff, I was thinking along the lines of a combobox at the top of the
form where all the tournaments can be listed. You'd then select a
tournament and then simply check each player that has entered that
tournament.

The problem with a lot of listboxes is that it is an awful lot of
clicking to droop down every listbox next to every player, select the
tournament and then move on to the next player.
 
M

MikeB

Ken, thanks, I've just reread what you wrote and I think it will do
the trick. My concern with the multi-list box for players is that the
list is potentially long and it might be easy to make mistakes by
clicking the wrong player, not clicking a player, having difficulty
when scrolling the list and so forth.

But at a pinch it will do.

Thanks
Mike
 
M

MikeB

Jeff, I must have had a comprehension problem when reading the replies
the first time. I apologize.

I don't understand why I'd have to rebuild the form each time the
number of players change, wouldn't it be possible to build some type
of form that has multiple rows?


Mike.
 
L

.Len B

Mike,
Couldn't you modify Ken's lstPlayers.RowSource to reduce the
number of players displayed based on, say, the qualification
criteria to enter the tournament. e.g. WHERE Sex = "M"
Maybe another combo for each possible qualification.
--
Len
______________________________________________________
remove nothing for valid email address.
Ken, thanks, I've just reread what you wrote and I think it will do
the trick. My concern with the multi-list box for players is that the
list is potentially long and it might be easy to make mistakes by
clicking the wrong player, not clicking a player, having difficulty
when scrolling the list and so forth.

But at a pinch it will do.

Thanks
Mike
 
M

MikeB

You guys have been very helpful. I'm going to go away and study
everything that's been said here.

Thanks again.

Mike

Taking up Len's suggestion you can restrict the list box's Rowsource.  You
could for instance add a combo box cboSex to the form with a RowSourceType
property of Value List and a RowSource property  of F;M.  In its AfterUpdate
event procedure requery the list box with:

Me.lstPlayers.Requery

Change the list box's RowSource property so it references the control as a
parameter:

SELECT PlayerID, FirstName & " " & LastName
FROM Players
WHERE (SEX = Form!cboSex OR Form!cboSex IS NULL)
ORDER BY LastName, FirstName;

You can add as many other controls as you wish to the form to restrict the
list further in the same way by including further references to parameters in
the WHERE clause, e.g.  to restrict the list to players of or below a certain
age at the time of a tournament by entering the age and tournament date in a
text boxes, on the basis of a DoB (date of birth) column in the Players table
if you have one:

SELECT PlayerID, FirstName & " " & LastName
FROM Players
WHERE (Sex = Form!cboSex OR Form!cboSex IS NULL)
AND (GetAge(DoB, Form!txtTournamentDate) <= Form!txtAge
OR  Form!txtAge IS NULL)
ORDER BY LastName, FirstName;

You'd use the following function to get the player's current age:

Public Function GetAge(varDob, Optional varDateAt)

    Dim intYears As Integer, intMonths As Integer

    ' return date at current date if no second argument
    ' passed into function
    If IsMissing(varDateAt) Or IsNull(varDateAt) Then
        varDateAt = VBA.Date
    End If

    If Not IsNull(varDob) Then
        ' get difference in years
        intYears = DateDiff("yyyy", varDob, varDateAt)
        ' get difference in months
        intMonths = DateDiff("m", varDob, _
            DateSerial(Year(varDob), Month(varDateAt), Day(varDateAt)))
        ' adjust result if date of birth falls later in year
        ' than date at which age to be calculated
        If varDateAt < DateSerial(Year(varDateAt), Month(varDob),Day(varDob))
Then
            intYears = intYears - 1
            intMonths = intMonths + 12
        End If

        GetAge = intYears & " year" & _
            IIf(intYears <> 1, "s", "") & ", " & _
            intMonths & " month" & _
            IIf(intMonths <> 1, "s", "")
    End If

End Function

If no tournament date is entered in the form then the current date will be
used to calculate the player's age.

Ken Sheridan
Stafford, England


Ken, thanks, I've just reread what you wrote and I think it will do
the trick. My concern with the multi-list box for players is that the
list is potentially long and it might be easy to make mistakes by
clicking the wrong player, not clicking  a player, having difficulty
when scrolling the list and so forth.
But at a pinch it will do.
Thanks
Mike

A better solution would be an unbound form with a multi-select list box of
players, a combo box to select the tournament and a button to inset the rows
[quoted text clipped - 86 lines]
 
J

Jeff Boyce

Without more information, I was only offering a possibility...

In my fevered imagination, I can imagine a form that uses a combobox to pick
the tournament, a listbox (on the left) to show available players, and a
listbox (on the right) that shows players signed up for the
(selected-in-combobox) tournament.

This approach has the advantage of allowing you to have ANY NUMBER OF
CHANGES to the players (and the tournaments, for that matter) and not have
to modify the form, the underlying queries -- you'd just add/modify a record
in a table...

Good luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

Jeff, I must have had a comprehension problem when reading the replies
the first time. I apologize.

I don't understand why I'd have to rebuild the form each time the
number of players change, wouldn't it be possible to build some type
of form that has multiple rows?


Mike.
 

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