Grouping numbers | | |
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 | | | | 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? | | | | 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.
> >
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. | | | | 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:
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? | | | | 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:
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 | | | | 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:
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. | | | | 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:
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 | | | | 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:
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 | | | | 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:
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 | | | | 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:
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 | | | | 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:
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..... | | | | 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:
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... | | | | 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:
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 |  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|