Hmmmmmmmmmmmm,
I made some alterations to
TLady's submission to suit my understanding of the question. I read the request as a SIMPLE (boolean):
Is the NEXT Wednesday in the Same MONTH as the (Wednesday) Date Supplied?
I (obviously) changed (notably SHORENED) the variable names and added a couple. Primarily because while I do not enjoy typing, I do use "Option Explicit", and thus NEED the declarations.
I also incorporated the entire process into the procedure, prefering to NOT rely on the User (or other programmer) for the calculation(s) beyond the "End Function" statement in the post.
Of course there needs to be SOME checking that the date supplied IS actually a "Wednesday" for the inquiry to make any sense. This, in turn implies an actual date be available to the routine. TLady's attempt to check this fails, as the arg is typed as DATE, so will ALWAYS have a value (even if it is ZERO), so the FIRST change is to cast the input arg as a variant - which can actually be missing I went a step further, and changed the check to simply require the arg to be a date.
This, of course, raises the issue of what should be done when / if the arg is NOT a wednesday or ANY valid date. I simply followed
TLady's lead and - for no date used the current date, and for dates which are not Wednesdays, used the precvious Wednesday. All of which ammount to quite nicely avoiding error checking and the need to construct an (elaborate) schema for the return value.
The remainder of the changes generally are the adaptations to incorporate all of the logic / computations within the procedure - and to simply return the status (boolean true false) to the calling process.
The following is (as ALWAYS) just a snippet, lacking error checking and even useful commentary, but it does return the boolean (flag) operator which I read as the expectation.
Code:
Function basWedInMo(Optional DateIn As Variant) As Boolean
'Michael Red 10/19/02 Tek-Tips thread181-383626
'Adapted from TLady Submission
'Sample Usage
'? basWedInMo
'True
'? basWedInMo(#10/28/02#)
'True
'? basWedInMo(#10/30/2002#)
'False
Dim LastWed As Date
Dim NxtWed As Date
Dim MoSuplWed As Integer
Dim MoNxtWed As Integer
If (Not IsDate(DateIn)) Then
DateIn = Date
End If
'Most Recent Wednesday
If (Weekday(DateIn) <> vbWednesday) Then
LastWed = DateAdd("d", (vbWednesday - Weekday(DateIn) - 7), DateIn)
Else
LastWed = DateIn
End If
NxtWed = DateAdd("ww", 1, LastWed)
'Get variables from DateIN as
MoSuplWed = Month(LastWed) 'Compareable month #
MoNxtWed = Month(NxtWed) 'Actual Month number
basWedInMo = (MoSuplWed = MoNxtWed)
End Function
crpjaviman,
Your 'procedure' looks simple, in part because it is incomplete. As a formal procedure, it lacks some nicieties (declaration and end statements), and a complete (missing type) declaration for
startw. It also relies on being in a form module, thus avoiding the declaration of some variables. And, as noted above, it does NOT check the given date is a Wednesday, or make any adjustment if it is not.
MichaelRed
m.red@att.net
There is never time to do it right but there is always time to do it over