russell576
Registered User.
- Local time
- Today, 14:42
- Joined
- Sep 19, 2014
- Messages
- 14
Earlier today I posted a thread ('SQL Error') which was answered very promptly. In the same database, on the same form, I have tried to update the last SQL to create the same table but with two amendments.
I want to produce a report of members' birthdays which used the query created in the original SQL (as amended on this forum). However, I couldn't get it to group the months in chronological order as the fields were all strings.
I amended my original query to create two more fields holding the integer values of the months and days, clicked on the SQL view and copied the code into the event procedure.
After a little modification, this is the code:
"SELECT Master.MemberID " & _
", Master.NameLast " & _
", Master.NameFirst " & _
", Master.NameFull " & _
", [NameFirst]+' '+[NameLast] AS FullName " & _
", Master.ClassName1 " & _
", Master.ClassName2 " & _
", Master.DOBMonth " & _
", IIf(IsNull(Master.DOBMonth), """" " & _
", MonthName(DOBMonth)) AS NameMonth " & _
", IIf(IsNull(Master.DOBMonth), '0'" & _
", CInt(DOBMonth)) AS MonthNum " & _
", Master.DOBDay " & _
", IIf(IsNull(Master.DOBDay), '0'" & _
", CInt(DOBDay)) AS DayNum " & _
", Master.Age " & _
", [Age]+1 AS AgeNext " & _
", Master.Left " & _
"FROM Master " & _
"WHERE Master.ClassName2 = '" & [Forms]![frmMenuReports]![cbxShowBirthdays] & "' " & _
"And Master.Left = False " & _
"ORDER BY Master.MonthNum, Master.DayNum;"
This time, it's the lines beginning with the function CInt that causes the problem. As before, the query as amended works, that is, I do get another two fields called MonthNum and DayNum calculated from the date of birth strings each containing numbers. But, this code falls over on the last line beginning ORDER. If I comment this out, the code runs but the MonthNum and DayNum fields contain the original strings from the DOBMonth & DOBDay fields respectively (though any fields with a Null value do get a zero) but the fields are all Strings.
So, the lines of code beginning CInt don't created integers.
Hope I've made myself clear and hope someone can help.
I want to produce a report of members' birthdays which used the query created in the original SQL (as amended on this forum). However, I couldn't get it to group the months in chronological order as the fields were all strings.
I amended my original query to create two more fields holding the integer values of the months and days, clicked on the SQL view and copied the code into the event procedure.
After a little modification, this is the code:
"SELECT Master.MemberID " & _
", Master.NameLast " & _
", Master.NameFirst " & _
", Master.NameFull " & _
", [NameFirst]+' '+[NameLast] AS FullName " & _
", Master.ClassName1 " & _
", Master.ClassName2 " & _
", Master.DOBMonth " & _
", IIf(IsNull(Master.DOBMonth), """" " & _
", MonthName(DOBMonth)) AS NameMonth " & _
", IIf(IsNull(Master.DOBMonth), '0'" & _
", CInt(DOBMonth)) AS MonthNum " & _
", Master.DOBDay " & _
", IIf(IsNull(Master.DOBDay), '0'" & _
", CInt(DOBDay)) AS DayNum " & _
", Master.Age " & _
", [Age]+1 AS AgeNext " & _
", Master.Left " & _
"FROM Master " & _
"WHERE Master.ClassName2 = '" & [Forms]![frmMenuReports]![cbxShowBirthdays] & "' " & _
"And Master.Left = False " & _
"ORDER BY Master.MonthNum, Master.DayNum;"
This time, it's the lines beginning with the function CInt that causes the problem. As before, the query as amended works, that is, I do get another two fields called MonthNum and DayNum calculated from the date of birth strings each containing numbers. But, this code falls over on the last line beginning ORDER. If I comment this out, the code runs but the MonthNum and DayNum fields contain the original strings from the DOBMonth & DOBDay fields respectively (though any fields with a Null value do get a zero) but the fields are all Strings.
So, the lines of code beginning CInt don't created integers.
Hope I've made myself clear and hope someone can help.