S
seeker
I have inserted a function in the criteria of a date field in a query and it
returns a data mismath error. Following is the sql and the function code.
The SQL
SELECT member_time.member_number, tblMemberNameandAddress.FirstName,
tblMemberNameandAddress.LastName, tblMemberNameandAddress.Address,
tblMemberNameandAddress.City, tblMemberNameandAddress.State,
tblMemberNameandAddress.ZipCode, tblMemberNameandAddress.PhoneNumber,
tblMemberNameandAddress.AltPhoneNumber,
Sum(DateDiff("n",member_time!time_in,member_time!time_out)/60) AS hours
FROM member_time INNER JOIN tblMemberNameandAddress ON
member_time.member_number = tblMemberNameandAddress.MemberNumber
WHERE (((member_time.date)=criteriachange(1)))
GROUP BY member_time.member_number, tblMemberNameandAddress.FirstName,
tblMemberNameandAddress.LastName, tblMemberNameandAddress.Address,
tblMemberNameandAddress.City, tblMemberNameandAddress.State,
tblMemberNameandAddress.ZipCode, tblMemberNameandAddress.PhoneNumber,
tblMemberNameandAddress.AltPhoneNumber
ORDER BY tblMemberNameandAddress.LastName;
the function which is called:
Function criteriachange(a As Integer) As String
Select Case DatePart("m", Date)
Case 1
Select Case a
Case 1
criteriachange = "between #12/1/08# and #12/31/08#"
Case 2
criteriachange = "between #11/1/08# and #11/30/08#"
Case 3
criteriachange = "between #10/1/08# and #10/31/08#"
Case 4
criteriachange = "between #9/1/08# and #9/30/08#"
Case 5
criteriachange = "between #8/1/08# and #8/31/08#"
Case 6
criteriachange = "between #7/1/08# and #7/31/08#"
End Select
Case 2
Select Case a
Case 1
criteriachange = "between #1/1/09# and #1/31/09#"
Case 2
criteriachange = "between #12/1/08# and #12/31/08#"
Case 3
criteriachange = "between #11/1/08# and #11/30/08#"
Case 4
criteriachange = "between #10/1/08# and #10/31/08#"
Case 5
criteriachange = "between #9/1/08# and #9/30/08#"
Case 6
criteriachange = "between #8/1/08# and #8/31/08#"
End Select
Case 3
Select Case a
Case 1
criteriachange = "between #2/1/09# and #2/28/09#"
Case 2
criteriachange = "between #1/1/09# and #1/31/09#"
Case 3
criteriachange = "between #12/1/08# and #12/31/08#"
Case 4
criteriachange = "between #11/1/08# and #11/30/08#"
Case 5
criteriachange = "between #10/1/08# and #10/31/08#"
Case 6
criteriachange = "between #9/1/08# and #9/30/08#"
End Select
Case 4
Select Case a
Case 1
criteriachange = "between #3/1/09# and #3/31/09#"
Case 2
criteriachange = "between #2/1/09# and #2/28/09#"
Case 3
criteriachange = "between #1/1/09# and #1/31/09#"
Case 4
criteriachange = "between #12/1/08# and #12/31/08#"
Case 5
criteriachange = "between #11/1/08# and #11/30/08#"
Case 6
criteriachange = "between #10/1/08# and #10/31/08#"
End Select
Case 5
Select Case a
Case 1
criteriachange = "between #4/1/09# and #4/30/09#"
Case 2
criteriachange = "between #3/1/09# and #3/31/09#"
Case 3
criteriachange = "between #2/1/09# and #2/28/09#"
Case 4
criteriachange = "between #1/1/09# and #1/31/09#"
Case 5
criteriachange = "between #12/1/08# and #12/31/08#"
Case 6
criteriachange = "between #11/1/08# and #11/30/08#"
End Select
Case 6
Select Case a
Case 1
criteriachange = "between #5/1/09# and #5/31/09#"
Case 2
criteriachange = "between #4/1/09# and #4/30/09#"
Case 3
criteriachange = "between #3/1/09# and #3/31/09#"
Case 4
criteriachange = "between #2/1/09# and #2/28/09#"
Case 5
criteriachange = "between #1/1/09# and #1/31/09#"
Case 6
criteriachange = "between #12/1/08# and #12/31/08#"
End Select
Case 7
Select Case a
Case 1
criteriachange = "between #6/1/09# and #6/30/09#"
Case 2
criteriachange = "between #5/1/09# and #5/31/09#"
Case 3
criteriachange = "between #4/1/09# and #4/30/09#"
Case 4
criteriachange = "between #3/1/09# and #3/31/09#"
Case 5
criteriachange = "between #2/1/09# and #2/28/09#"
Case 6
criteriachange = "between #1/1/09# and #1/31/09#"
End Select
Case 8
Select Case a
Case 1
criteriachange = "between #7/1/09# and #7/31/09#"
Case 2
criteriachange = "between #6/1/09# and #6/30/09#"
Case 3
criteriachange = "between #5/1/09# and #5/31/09#"
Case 4
criteriachange = "between #4/1/09# and #4/30/09#"
Case 5
criteriachange = "between #3/1/09# and #3/31/09#"
Case 6
criteriachange = "between #2/1/09# and #2/28/09#"
End Select
Case 9
Select Case a
Case 1
criteriachange = "between #8/1/09# and #8/31/09#"
Case 2
criteriachange = "between #7/1/09# and #7/31/09#"
Case 3
criteriachange = "between #6/1/09# and #6/30/09#"
Case 4
criteriachange = "between #5/1/09# and #5/31/09#"
Case 5
criteriachange = "between #4/1/09# and #4/30/09#"
Case 6
criteriachange = "between #3/1/09# and #3/31/09#"
End Select
Case 10
Select Case a
Case 1
criteriachange = "between #9/1/09# and #9/30/09#"
Case 2
criteriachange = "between #8/1/09# and #8/31/09#"
Case 3
criteriachange = "between #7/1/09# and #7/31/09#"
Case 4
criteriachange = "between #6/1/09# and #6/30/09#"
Case 5
criteriachange = "between #5/1/09# and #5/31/09#"
Case 6
criteriachange = "between #4/1/09# and #4/30/09#"
End Select
Case 11
Select Case a
Case 1
criteriachange = "between #10/1/09# and #10/31/09#"
Case 2
criteriachange = "between #9/1/09# and #9/30/09#"
Case 3
criteriachange = "between #8/1/09# and #8/31/09#"
Case 4
criteriachange = "between #7/1/09# and #7/31/09#"
Case 5
criteriachange = "between #6/1/09# and #6/30/09#"
Case 6
criteriachange = "between #5/1/09# and #5/30/09#"
End Select
Case 12
Select Case a
Case 1
criteriachange = "between #11/1/09# and #11/30/09#"
Case 2
criteriachange = "between #10/1/09# and #10/31/09#"
Case 3
criteriachange = "between #9/1/09# and #9/30/09#"
Case 4
criteriachange = "between #8/1/09# and #8/31/09#"
Case 5
criteriachange = "between #7/1/09# and #7/31/09#"
Case 6
criteriachange = "between #6/1/09# and #6/30/09#"
End Select
End Select
End Function
What is causing the error??? Thanks
returns a data mismath error. Following is the sql and the function code.
The SQL
SELECT member_time.member_number, tblMemberNameandAddress.FirstName,
tblMemberNameandAddress.LastName, tblMemberNameandAddress.Address,
tblMemberNameandAddress.City, tblMemberNameandAddress.State,
tblMemberNameandAddress.ZipCode, tblMemberNameandAddress.PhoneNumber,
tblMemberNameandAddress.AltPhoneNumber,
Sum(DateDiff("n",member_time!time_in,member_time!time_out)/60) AS hours
FROM member_time INNER JOIN tblMemberNameandAddress ON
member_time.member_number = tblMemberNameandAddress.MemberNumber
WHERE (((member_time.date)=criteriachange(1)))
GROUP BY member_time.member_number, tblMemberNameandAddress.FirstName,
tblMemberNameandAddress.LastName, tblMemberNameandAddress.Address,
tblMemberNameandAddress.City, tblMemberNameandAddress.State,
tblMemberNameandAddress.ZipCode, tblMemberNameandAddress.PhoneNumber,
tblMemberNameandAddress.AltPhoneNumber
ORDER BY tblMemberNameandAddress.LastName;
the function which is called:
Function criteriachange(a As Integer) As String
Select Case DatePart("m", Date)
Case 1
Select Case a
Case 1
criteriachange = "between #12/1/08# and #12/31/08#"
Case 2
criteriachange = "between #11/1/08# and #11/30/08#"
Case 3
criteriachange = "between #10/1/08# and #10/31/08#"
Case 4
criteriachange = "between #9/1/08# and #9/30/08#"
Case 5
criteriachange = "between #8/1/08# and #8/31/08#"
Case 6
criteriachange = "between #7/1/08# and #7/31/08#"
End Select
Case 2
Select Case a
Case 1
criteriachange = "between #1/1/09# and #1/31/09#"
Case 2
criteriachange = "between #12/1/08# and #12/31/08#"
Case 3
criteriachange = "between #11/1/08# and #11/30/08#"
Case 4
criteriachange = "between #10/1/08# and #10/31/08#"
Case 5
criteriachange = "between #9/1/08# and #9/30/08#"
Case 6
criteriachange = "between #8/1/08# and #8/31/08#"
End Select
Case 3
Select Case a
Case 1
criteriachange = "between #2/1/09# and #2/28/09#"
Case 2
criteriachange = "between #1/1/09# and #1/31/09#"
Case 3
criteriachange = "between #12/1/08# and #12/31/08#"
Case 4
criteriachange = "between #11/1/08# and #11/30/08#"
Case 5
criteriachange = "between #10/1/08# and #10/31/08#"
Case 6
criteriachange = "between #9/1/08# and #9/30/08#"
End Select
Case 4
Select Case a
Case 1
criteriachange = "between #3/1/09# and #3/31/09#"
Case 2
criteriachange = "between #2/1/09# and #2/28/09#"
Case 3
criteriachange = "between #1/1/09# and #1/31/09#"
Case 4
criteriachange = "between #12/1/08# and #12/31/08#"
Case 5
criteriachange = "between #11/1/08# and #11/30/08#"
Case 6
criteriachange = "between #10/1/08# and #10/31/08#"
End Select
Case 5
Select Case a
Case 1
criteriachange = "between #4/1/09# and #4/30/09#"
Case 2
criteriachange = "between #3/1/09# and #3/31/09#"
Case 3
criteriachange = "between #2/1/09# and #2/28/09#"
Case 4
criteriachange = "between #1/1/09# and #1/31/09#"
Case 5
criteriachange = "between #12/1/08# and #12/31/08#"
Case 6
criteriachange = "between #11/1/08# and #11/30/08#"
End Select
Case 6
Select Case a
Case 1
criteriachange = "between #5/1/09# and #5/31/09#"
Case 2
criteriachange = "between #4/1/09# and #4/30/09#"
Case 3
criteriachange = "between #3/1/09# and #3/31/09#"
Case 4
criteriachange = "between #2/1/09# and #2/28/09#"
Case 5
criteriachange = "between #1/1/09# and #1/31/09#"
Case 6
criteriachange = "between #12/1/08# and #12/31/08#"
End Select
Case 7
Select Case a
Case 1
criteriachange = "between #6/1/09# and #6/30/09#"
Case 2
criteriachange = "between #5/1/09# and #5/31/09#"
Case 3
criteriachange = "between #4/1/09# and #4/30/09#"
Case 4
criteriachange = "between #3/1/09# and #3/31/09#"
Case 5
criteriachange = "between #2/1/09# and #2/28/09#"
Case 6
criteriachange = "between #1/1/09# and #1/31/09#"
End Select
Case 8
Select Case a
Case 1
criteriachange = "between #7/1/09# and #7/31/09#"
Case 2
criteriachange = "between #6/1/09# and #6/30/09#"
Case 3
criteriachange = "between #5/1/09# and #5/31/09#"
Case 4
criteriachange = "between #4/1/09# and #4/30/09#"
Case 5
criteriachange = "between #3/1/09# and #3/31/09#"
Case 6
criteriachange = "between #2/1/09# and #2/28/09#"
End Select
Case 9
Select Case a
Case 1
criteriachange = "between #8/1/09# and #8/31/09#"
Case 2
criteriachange = "between #7/1/09# and #7/31/09#"
Case 3
criteriachange = "between #6/1/09# and #6/30/09#"
Case 4
criteriachange = "between #5/1/09# and #5/31/09#"
Case 5
criteriachange = "between #4/1/09# and #4/30/09#"
Case 6
criteriachange = "between #3/1/09# and #3/31/09#"
End Select
Case 10
Select Case a
Case 1
criteriachange = "between #9/1/09# and #9/30/09#"
Case 2
criteriachange = "between #8/1/09# and #8/31/09#"
Case 3
criteriachange = "between #7/1/09# and #7/31/09#"
Case 4
criteriachange = "between #6/1/09# and #6/30/09#"
Case 5
criteriachange = "between #5/1/09# and #5/31/09#"
Case 6
criteriachange = "between #4/1/09# and #4/30/09#"
End Select
Case 11
Select Case a
Case 1
criteriachange = "between #10/1/09# and #10/31/09#"
Case 2
criteriachange = "between #9/1/09# and #9/30/09#"
Case 3
criteriachange = "between #8/1/09# and #8/31/09#"
Case 4
criteriachange = "between #7/1/09# and #7/31/09#"
Case 5
criteriachange = "between #6/1/09# and #6/30/09#"
Case 6
criteriachange = "between #5/1/09# and #5/30/09#"
End Select
Case 12
Select Case a
Case 1
criteriachange = "between #11/1/09# and #11/30/09#"
Case 2
criteriachange = "between #10/1/09# and #10/31/09#"
Case 3
criteriachange = "between #9/1/09# and #9/30/09#"
Case 4
criteriachange = "between #8/1/09# and #8/31/09#"
Case 5
criteriachange = "between #7/1/09# and #7/31/09#"
Case 6
criteriachange = "between #6/1/09# and #6/30/09#"
End Select
End Select
End Function
What is causing the error??? Thanks