The following code was recently worked on....but I believe it still need some tweaking....
if user enters an invalid date in frmGetdateFiling.txtGetdateFiling, I recieved an Invalid date msgbox,
hoever the code is expected to give me 3 other attempts before shutting down db..this is not havppening.
Instead I get a message that I have no attempt left even though user has only invalid date once. How do I correct this?
'Title for message boxes, change as u see fit
Private Const FRM_TITLE = "Filing Date"
'Define the number of days for your grace period here
Private Const GRACE_PERIOD = 14
'Define the max number of attemps possible
Private Const MAX_FAILED_ATTEMPTS = 3
'This variable is used to record the number of times the date entered is invalid
Dim m_iNoAttempts As Integer
Public Function GracePeriodValidation(ByVal dValDate As Date, ByVal iQQ As Integer, ByVal iYY As Integer) As Boolean
Dim iGracePeriod As Integer
Dim dLastDate As Date
Dim dCheckDate As Date
'Get the quarter to file. If quarter 1 then for previous quarter, we need to subtract the year also
'Here we define the grace period
'It might be useful if u define is 14 as a constant
'or store it in sum lookup table
iGracePeriod = GRACE_PERIOD
'Get last date, calculated using DateSerial
'Pass in current year, then month is calculated by multiplying current quarter by 3
'then we add 1, so we end up the following month
'the last parameter is 0, which means we take away one day
'thus giving us the last day of the previous month i.e. end of quarter
dLastDate = DateSerial(iYY, (iQQ * 3) + 1, 0)
'Check current date is within the filing date period
'Return false if invalid, TRUE otherwise
If dValDate < dLastDate Or dValDate > DateAdd("d", GRACE_PERIOD + 1, dLastDate) Then '<<-- I changed this line from 14 to 15
GracePeriodValidation = False
GracePeriodValidation = True