Connecting Tech Pros Worldwide Forums | Help | Site Map

Grouping numbers

Chris
Guest
 
Posts: n/a
#1: Mar 4 '07
I have a table which lists player names, teams played for and the
years they played there and my code looks like this

SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;

which takes the Min year and the Max Year and displays it like "Year-
Year"

But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995

It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.

PLEASE HELP


Gord
Guest
 
Posts: n/a
#2: Mar 4 '07

re: Grouping numbers


On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
PLEASE HELP
Hi, Chris. I see you're still struggling with this problem. Give this
a try:

1. Paste the following code into a new Module in your Access database:

Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String

Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function


2. Change your query to

SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;


Does that do it?

Chris
Guest
 
Posts: n/a
#3: Mar 4 '07

re: Grouping numbers


On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
>
>
>
>
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
PLEASE HELP
>
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
1. Paste the following code into a new Module in your Access database:
>
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
2. Change your query to
>
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Does that do it?- Hide quoted text -
>
- Show quoted text -
I get an error that says "undefined function 'ListYears' in Expression.

Gord
Guest
 
Posts: n/a
#4: Mar 4 '07

re: Grouping numbers


On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
>
>
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
2. Change your query to
>
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Does that do it?- Hide quoted text -
>
Quote:
- Show quoted text -
>
I get an error that says "undefined function 'ListYears' in Expression.
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?

2. Are you are running the query from within Access?

Chris
Guest
 
Posts: n/a
#5: Mar 4 '07

re: Grouping numbers


On Mar 4, 10:03 am, "Gord" <g...@kingston.netwrote:
Quote:
On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
>
>
>
>
>
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
Quote:
2. Change your query to
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Quote:
Does that do it?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
I get an error that says "undefined function 'ListYears' in Expression.
>
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?
>
2. Are you are running the query from within Access?- Hide quoted text -
>
- Show quoted text -
What I did was clicked on modules under objects clicked new and pasted
the code in there saved it as ListYears then ran the query. Sorry if
im not writying it correctly but I am a newbie at this

Gord
Guest
 
Posts: n/a
#6: Mar 4 '07

re: Grouping numbers


On Mar 4, 10:28 am, "Chris" <chrislab...@gmail.comwrote:
Quote:
On Mar 4, 10:03 am, "Gord" <g...@kingston.netwrote:
>
>
>
Quote:
On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
Quote:
2. Change your query to
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Quote:
Does that do it?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
I get an error that says "undefined function 'ListYears' in Expression.
>
Quote:
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?
>
Quote:
2. Are you are running the query from within Access?- Hide quoted text -
>
Quote:
- Show quoted text -
>
What I did was clicked on modules under objects clicked new and pasted
the code in there saved it as ListYears then ran the query. Sorry if
im not writying it correctly but I am a newbie at this
Aha. The name of the module shouldn't be the same as the name of the
function inside it. Rename the module to "modListYears" or "Module1"
or something, then try again.

Chris
Guest
 
Posts: n/a
#7: Mar 4 '07

re: Grouping numbers


On Mar 4, 10:41 am, "Gord" <g...@kingston.netwrote:
Quote:
On Mar 4, 10:28 am, "Chris" <chrislab...@gmail.comwrote:
>
>
>
>
>
Quote:
On Mar 4, 10:03 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
Quote:
2. Change your query to
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Quote:
Does that do it?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
I get an error that says "undefined function 'ListYears' in Expression.
>
Quote:
Quote:
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?
>
Quote:
Quote:
2. Are you are running the query from within Access?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
What I did was clicked on modules under objects clicked new and pasted
the code in there saved it as ListYears then ran the query. Sorry if
im not writying it correctly but I am a newbie at this
>
Aha. The name of the module shouldn't be the same as the name of the
function inside it. Rename the module to "modListYears" or "Module1"
or something, then try again.- Hide quoted text -
>
- Show quoted text -
okay now I get a Run-time error '3061'
Too Few parameters. Expected 2

Thank you so much for your help

Gord
Guest
 
Posts: n/a
#8: Mar 4 '07

re: Grouping numbers


On Mar 4, 11:09 am, "Chris" <chrislab...@gmail.comwrote:
Quote:
On Mar 4, 10:41 am, "Gord" <g...@kingston.netwrote:
>
>
>
Quote:
On Mar 4, 10:28 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:03 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
Quote:
2. Change your query to
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Quote:
Does that do it?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
I get an error that says "undefined function 'ListYears' in Expression.
>
Quote:
Quote:
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?
>
Quote:
Quote:
2. Are you are running the query from within Access?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
What I did was clicked on modules under objects clicked new and pasted
the code in there saved it as ListYears then ran the query. Sorry if
im not writying it correctly but I am a newbie at this
>
Quote:
Aha. The name of the module shouldn't be the same as the name of the
function inside it. Rename the module to "modListYears" or "Module1"
or something, then try again.- Hide quoted text -
>
Quote:
- Show quoted text -
>
okay now I get a Run-time error '3061'
Too Few parameters. Expected 2
>
Thank you so much for your help
What are the data types for the columns in your [AlsoPlayedFor] table?
I assumed that they were:

playerID: Long Integer
teamID: Long Integer
Year: Integer

Chris
Guest
 
Posts: n/a
#9: Mar 4 '07

re: Grouping numbers


On Mar 4, 12:29 pm, "Gord" <g...@kingston.netwrote:
Quote:
On Mar 4, 11:09 am, "Chris" <chrislab...@gmail.comwrote:
>
>
>
>
>
Quote:
On Mar 4, 10:41 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 10:28 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:03 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
Quote:
2. Change your query to
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Quote:
Does that do it?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
I get an error that says "undefined function 'ListYears' in Expression.
>
Quote:
Quote:
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?
>
Quote:
Quote:
2. Are you are running the query from within Access?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
What I did was clicked on modules under objects clicked new and pasted
the code in there saved it as ListYears then ran the query. Sorry if
im not writying it correctly but I am a newbie at this
>
Quote:
Quote:
Aha. The name of the module shouldn't be the same as the name of the
function inside it. Rename the module to "modListYears" or "Module1"
or something, then try again.- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
okay now I get a Run-time error '3061'
Too Few parameters. Expected 2
>
Quote:
Thank you so much for your help
>
What are the data types for the columns in your [AlsoPlayedFor] table?
I assumed that they were:
>
playerID: Long Integer
teamID: Long Integer
Year: Integer- Hide quoted text -
>
- Show quoted text -
playerID: Text
teamID: Text
Year: Number

Gord
Guest
 
Posts: n/a
#10: Mar 4 '07

re: Grouping numbers


On Mar 4, 12:31 pm, "Chris" <chrislab...@gmail.comwrote:
Quote:
On Mar 4, 12:29 pm, "Gord" <g...@kingston.netwrote:
>
>
>
Quote:
On Mar 4, 11:09 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:41 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 10:28 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:03 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
Quote:
2. Change your query to
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Quote:
Does that do it?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
I get an error that says "undefined function 'ListYears' in Expression.
>
Quote:
Quote:
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?
>
Quote:
Quote:
2. Are you are running the query from within Access?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
What I did was clicked on modules under objects clicked new and pasted
the code in there saved it as ListYears then ran the query. Sorry if
im not writying it correctly but I am a newbie at this
>
Quote:
Quote:
Aha. The name of the module shouldn't be the same as the name of the
function inside it. Rename the module to "modListYears" or "Module1"
or something, then try again.- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
okay now I get a Run-time error '3061'
Too Few parameters. Expected 2
>
Quote:
Quote:
Thank you so much for your help
>
Quote:
What are the data types for the columns in your [AlsoPlayedFor] table?
I assumed that they were:
>
Quote:
playerID: Long Integer
teamID: Long Integer
Year: Integer- Hide quoted text -
>
Quote:
- Show quoted text -
>
playerID: Text
teamID: Text
Year: Number
Okay, use this code instead:

Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String

Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]='" & playerID & "' " & _
"AND [teamID]='" & teamID & "' " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function

Chris
Guest
 
Posts: n/a
#11: Mar 4 '07

re: Grouping numbers


On Mar 4, 12:50 pm, "Gord" <g...@kingston.netwrote:
Quote:
On Mar 4, 12:31 pm, "Chris" <chrislab...@gmail.comwrote:
>
>
>
>
>
Quote:
On Mar 4, 12:29 pm, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 11:09 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:41 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 10:28 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:03 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
Quote:
2. Change your query to
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Quote:
Does that do it?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
I get an error that says "undefined function 'ListYears' in Expression.
>
Quote:
Quote:
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?
>
Quote:
Quote:
2. Are you are running the query from within Access?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
What I did was clicked on modules under objects clicked new and pasted
the code in there saved it as ListYears then ran the query. Sorry if
im not writying it correctly but I am a newbie at this
>
Quote:
Quote:
Aha. The name of the module shouldn't be the same as the name of the
function inside it. Rename the module to "modListYears" or "Module1"
or something, then try again.- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
okay now I get a Run-time error '3061'
Too Few parameters. Expected 2
>
Quote:
Quote:
Thank you so much for your help
>
Quote:
Quote:
What are the data types for the columns in your [AlsoPlayedFor] table?
I assumed that they were:
>
Quote:
Quote:
playerID: Long Integer
teamID: Long Integer
Year: Integer- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
playerID: Text
teamID: Text
Year: Number
>
Okay, use this code instead:
>
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]='" & playerID & "' " & _
"AND [teamID]='" & teamID & "' " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function- Hide quoted text -
>
- Show quoted text -
Your a Genius, thank you so much.....

Chris
Guest
 
Posts: n/a
#12: Mar 4 '07

re: Grouping numbers


On Mar 4, 1:03 pm, "Chris" <chrislab...@gmail.comwrote:
Quote:
On Mar 4, 12:50 pm, "Gord" <g...@kingston.netwrote:
>
>
>
>
>
Quote:
On Mar 4, 12:31 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 12:29 pm, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 11:09 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:41 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 10:28 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:03 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
Quote:
2. Change your query to
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Quote:
Does that do it?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
I get an error that says "undefined function 'ListYears' in Expression.
>
Quote:
Quote:
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?
>
Quote:
Quote:
2. Are you are running the query from within Access?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
What I did was clicked on modules under objects clicked new and pasted
the code in there saved it as ListYears then ran the query. Sorry if
im not writying it correctly but I am a newbie at this
>
Quote:
Quote:
Aha. The name of the module shouldn't be the same as the name of the
function inside it. Rename the module to "modListYears" or "Module1"
or something, then try again.- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
okay now I get a Run-time error '3061'
Too Few parameters. Expected 2
>
Quote:
Quote:
Thank you so much for your help
>
Quote:
Quote:
What are the data types for the columns in your [AlsoPlayedFor] table?
I assumed that they were:
>
Quote:
Quote:
playerID: Long Integer
teamID: Long Integer
Year: Integer- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
playerID: Text
teamID: Text
Year: Number
>
Quote:
Okay, use this code instead:
>
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]='" & playerID & "' " & _
"AND [teamID]='" & teamID & "' " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function- Hide quoted text -
>
Quote:
- Show quoted text -
>
Your a Genius, thank you so much.....- Hide quoted text -
>
- Show quoted text -
okay so I added some new records to my table now when I run the query
it only displayes the lowest year instead of groupig them together...

Gord
Guest
 
Posts: n/a
#13: Mar 4 '07

re: Grouping numbers


On Mar 4, 1:42 pm, "Chris" <chrislab...@gmail.comwrote:
Quote:
On Mar 4, 1:03 pm, "Chris" <chrislab...@gmail.comwrote:
>
>
>
Quote:
On Mar 4, 12:50 pm, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 12:31 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 12:29 pm, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 11:09 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:41 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 10:28 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 10:03 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 4, 9:15 am, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
On Mar 4, 6:32 am, "Gord" <g...@kingston.netwrote:
>
Quote:
Quote:
On Mar 3, 11:54 pm, "Chris" <chrislab...@gmail.comwrote:
>
Quote:
Quote:
I have a table which lists player names, teams played for and the
years they played there and my code looks like this
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" &
Max([AlsoPlayedFor].[Year]) AS [Year]
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
AlsoPlayedFor.TeamName;
>
Quote:
Quote:
which takes the Min year and the Max Year and displays it like "Year-
Year"
>
Quote:
Quote:
But lets say for example the player played for 5 years so it 1990,
1991, 1992, 1993, 1995
>
Quote:
Quote:
It would display as 1990-1995 but I want it to display as 1990-1993,
1995, is this possiable??? Also I need it to gothe other wayso if the
years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990,
1992-1995.
>
Quote:
Quote:
PLEASE HELP
>
Quote:
Quote:
Hi, Chris. I see you're still struggling with this problem. Give this
a try:
>
Quote:
Quote:
1. Paste the following code into a new Module in your Access database:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]=" & playerID & " " & _
"AND [teamID]=" & teamID & " " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function
>
Quote:
Quote:
2. Change your query to
>
Quote:
Quote:
SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID,
ListYears([playerID],[teamID]) AS Years
FROM AlsoPlayedFor
GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID;
>
Quote:
Quote:
Does that do it?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
I get an error that says "undefined function 'ListYears' in Expression.
>
Quote:
Quote:
1. Did you paste the VBA code into a new Access Module (a regular
Module, not a Class Module) and save it?
>
Quote:
Quote:
2. Are you are running the query from within Access?- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
What I did was clicked on modules under objects clicked new and pasted
the code in there saved it as ListYears then ran the query. Sorry if
im not writying it correctly but I am a newbie at this
>
Quote:
Quote:
Aha. The name of the module shouldn't be the same as the name of the
function inside it. Rename the module to "modListYears" or "Module1"
or something, then try again.- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
okay now I get a Run-time error '3061'
Too Few parameters. Expected 2
>
Quote:
Quote:
Thank you so much for your help
>
Quote:
Quote:
What are the data types for the columns in your [AlsoPlayedFor] table?
I assumed that they were:
>
Quote:
Quote:
playerID: Long Integer
teamID: Long Integer
Year: Integer- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Quote:
playerID: Text
teamID: Text
Year: Number
>
Quote:
Quote:
Okay, use this code instead:
>
Quote:
Quote:
Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String
>
Quote:
Quote:
Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]='" & playerID & "' " & _
"AND [teamID]='" & teamID & "' " & _
"ORDER BY [Year]", _
dbOpenSnapshot)
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(seqStart <prevYear, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ListYears = Mid(strList, 3)
End Function- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -
>
Quote:
Your a Genius, thank you so much.....- Hide quoted text -
>
Quote:
- Show quoted text -
>
okay so I added some new records to my table now when I run the query
it only displayes the lowest year instead of groupig them together...
Rats. End conditions. Try this:

Public Function ListYears(playerID, teamID)
Dim _
rst As DAO.Recordset, _
prevYear As Integer, _
seqStart As Integer, _
strList As String

Set rst = CurrentDb.OpenRecordset( _
"SELECT [Year] FROM [AlsoPlayedFor] " & _
"WHERE [playerID]='" & playerID & "' " & _
"AND [teamID]='" & teamID & "' " & _
"ORDER BY [Year]", _
dbOpenSnapshot)

If rst.EOF Then
ListYears = ""
Else
strList = ""
prevYear = 0
seqStart = 0
Do While Not rst.EOF
If rst!Year <prevYear + 1 Then
strList = strList & _
IIf(prevYear <seqStart, "-" & prevYear, "") & _
", " & _
rst!Year
seqStart = rst!Year
End If
prevYear = rst!Year
rst.MoveNext
Loop
If prevYear <seqStart Then
strList = strList & "-" & prevYear
End If
ListYears = Mid(strList, 3)
End If
rst.Close
Set rst = Nothing
End Function

Closed Thread


Similar Microsoft Access / VBA bytes