Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot select Sunday only records in WHERE statement

Status
Not open for further replies.

KavJack

Programmer
Apr 1, 2001
46
0
0
My query qryGDATE3 won't work.
I get message "Data type mismatch in criteria expression" on execution.


qryGDATE2 does work correctly.
I just want to select all the results that come up with a DOW equal to "Sunday".
How can I make this work ?

Query - qryGDATE1
SELECT N_League.*
FROM N_League
WHERE GDATE>0 AND GDATE-10000*INT(GDATE/10000)>0;

Query - qryGDATE2

SELECT qryGDATE1.*, FuncWkd(qryGDATE1.GDATE) AS DOW
FROM qryGDATE1
ORDER BY SEASON, GDATE;

Query - qryGDATE3

SELECT qryGDATE2.*, qryGDATE2.DOW
FROM qryGDATE2
WHERE (((qryGDATE2.DOW)="Sunday"));


Function FuncWkd(InDate As Long) As String

Dim IntX As Long
Dim GDATE As Date
Dim Day As Long
Dim Month As Long
Dim Year As Long

Year = InDate / 10000
Month = (InDate - (Year * 10000)) / 100
If (Month = 0) Then GoTo Err:

Day = (InDate - ((Year * 10000) + (Month * 100)))
GDATE = Str(Month) & "/" & Str(Day) & "/" & Str(Year)
IntX = Weekday(GDATE)
If (IntX = 0) Then IntX = 7
FuncWkd = WeekdayName(IntX)

On Error GoTo Err:


Exit Function
Err:
FuncWkd = "No Date"
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description


Exit Function
End Function

My GDATE field has a data type of double integer, i.e a date such as 7th Dec. 1977 is held as the number 19771207

CStr function didn't work

SELECT qryGDATE2.*, qryGDATE2.DOW
FROM qryGDATE2
WHERE CStr(qryGDATE2.DOW)=CStr("Sunday");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top