Reference Thread thread705-1453739
Greetings, I am using CK1999's code I keep getting a debug error when executed. The error says there is Syntax error in from clause. The VBA code errors out at line
Set rst = dbs.OpenRecordset(strSql)
I don't get it. I've checked my tabel name, field name everything I can think of with no luck.
Any suggestions would greatly help.
my holiday table name is tbl_H and field name is HDate all date formats are the same in all my tables.
Public Function basDlyHrs(StDt As Date, EndDt As Date) As Double
'Michhael Red 1/1/2003 Working Hours?
'Tek-Tips thread705-449121 for "Chargers"
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim Idx As Long
Dim StrtTim As Date
Dim EndTim As Date
Dim dtSt As Date
Dim dtEnd As Date
Dim TheDate As Date
Dim DlyHrs As Single
Dim strCriteria As String
Dim strSql As String
StrtTim = #7:00:00 AM#
EndTim = #4:00:00 PM#
DlyHrs = DateDiff("n", StrtTim, EndTim) / 60
dtSt = Format(StDt, "Short Date")
dtEnd = Format(EndDt, "Short Date")
'Create an Array to hold the Time for Each Day
' Dim MyDates() As MyDtHrsType
'Resize array for each DAY
' ReDim MyDates(dtEnd - dtSt + 1)
'Get Holidates
Set dbs = CurrentDb
strCriteria = "(HDate Between " & Chr(35) & dtSt & Chr(35) & _
" AND " & Chr(35) & dtEnd & Chr(35) & ")"
strSql = "Select HDate "
strSql = strSql & "from tbl_H"
strSql = strSql & "Where "
strSql = strSql & strCriteria & ";"
Set rst = dbs.OpenRecordset(strSql)
Dim holidaycount
holidaycount = 0
rst.MoveFirst
Do While Not rst.EOF
If (Weekday(rst("HDate"), vbMonday) > 5) Then
holidaycount = holidaycount + 1
End If
rst.MoveNext
Loop
' next line from datecount = DateDiff("d", dtSt, dtEnd) - DateDiff("ww", dtSt, dtEnd, 1) * 2 - IIf(Weekday(dtEnd, 1) = 7, IIf(Weekday(dtSt, 1) = 7, 0, 1), IIf(Weekday(dtSt, 1) = 7, -1, 0)) + 1
datecount = datecount - holidaycount
basDlyHrs = datecount * DlyHrs
Set dbs = Nothing
End Function
Greetings, I am using CK1999's code I keep getting a debug error when executed. The error says there is Syntax error in from clause. The VBA code errors out at line
Set rst = dbs.OpenRecordset(strSql)
I don't get it. I've checked my tabel name, field name everything I can think of with no luck.
Any suggestions would greatly help.
my holiday table name is tbl_H and field name is HDate all date formats are the same in all my tables.
Public Function basDlyHrs(StDt As Date, EndDt As Date) As Double
'Michhael Red 1/1/2003 Working Hours?
'Tek-Tips thread705-449121 for "Chargers"
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim Idx As Long
Dim StrtTim As Date
Dim EndTim As Date
Dim dtSt As Date
Dim dtEnd As Date
Dim TheDate As Date
Dim DlyHrs As Single
Dim strCriteria As String
Dim strSql As String
StrtTim = #7:00:00 AM#
EndTim = #4:00:00 PM#
DlyHrs = DateDiff("n", StrtTim, EndTim) / 60
dtSt = Format(StDt, "Short Date")
dtEnd = Format(EndDt, "Short Date")
'Create an Array to hold the Time for Each Day
' Dim MyDates() As MyDtHrsType
'Resize array for each DAY
' ReDim MyDates(dtEnd - dtSt + 1)
'Get Holidates
Set dbs = CurrentDb
strCriteria = "(HDate Between " & Chr(35) & dtSt & Chr(35) & _
" AND " & Chr(35) & dtEnd & Chr(35) & ")"
strSql = "Select HDate "
strSql = strSql & "from tbl_H"
strSql = strSql & "Where "
strSql = strSql & strCriteria & ";"
Set rst = dbs.OpenRecordset(strSql)
Dim holidaycount
holidaycount = 0
rst.MoveFirst
Do While Not rst.EOF
If (Weekday(rst("HDate"), vbMonday) > 5) Then
holidaycount = holidaycount + 1
End If
rst.MoveNext
Loop
' next line from datecount = DateDiff("d", dtSt, dtEnd) - DateDiff("ww", dtSt, dtEnd, 1) * 2 - IIf(Weekday(dtEnd, 1) = 7, IIf(Weekday(dtSt, 1) = 7, 0, 1), IIf(Weekday(dtSt, 1) = 7, -1, 0)) + 1
datecount = datecount - holidaycount
basDlyHrs = datecount * DlyHrs
Set dbs = Nothing
End Function