Hey guys,
I have a simple function that finds the first date of the current pay period:
This code works just fine when set as the default date for a textbook on a form as well as just running it on the immediate window. I have a sub that does quite a bit, but at the very beginning, i was getting a Type Mismatch error. For testing, I added a line right after the Dims:Code:Public Function DateFrom(Today As Date) As Date 'if Today is the first day of the pay period, then pull the entire last period If DatePart("ww", Today, vbMonday, vbFirstFullWeek) Mod 2 = 0 And _ DatePart("w", Today, vbMonday, vbFirstFullWeek) = 1 Then DateFrom = Today - 14 Else ' determine if current day is in 1st or 2nd week of pay period ' 1st weeks are odd, 2nd are even Dim DayMod As Integer If DatePart("ww", Today, vbMonday, vbFirstFullWeek) Mod 2 = 1 Then DayMod = 7 Else DayMod = 0 End If 'determine how many days back you need to go to get to monday 'of the first week in the pay period DayMod = DayMod + (DatePart("w", Today, vbMonday, vbFirstFullWeek) - 1) DateFrom = DateAdd("d", -1 * DayMod, Today) End If End Function
I'm still getting the error on that. Any idea what is going on??Code:debug.print DateFrom(Date)


Type Mismatch in Sub, but not when using the function alone
Reply With Quote

