Question Select Case between to dates VBA

DanJames

Registered User.
Local time
Yesterday, 20:31
Joined
Sep 3, 2009
Messages
78
Select Case between two dates VBA

I am trying to change the visibility of a label depending on a date in the Next_Payment_Due text box. I have used the select case method eg:

Code:
Select Case Next_Payment_Due.Value
Case Is >= Date - 25
PDS.Visible = True
Case Is <= Date + 5
Case Else
PDS.Visible = False
End Select
Say the date today is 05/01/10, and a date in the text box was 08/01/10 I would want the visibilty true.

Thanks in advance,
Dan
 
Last edited:
Re: Select Case between two dates VBA

I am trying to change the visibility of a label depending on a date in the Next_Payment_Due text box. I have used the select case method eg:

Code:
Select Case Next_Payment_Due.Value
Case Is >= Date - 25
PDS.Visible = True
Case Is <= Date + 5
Case Else
PDS.Visible = False
End Select
Say the date today is 05/01/10, and a date in the text box was 08/01/10 I would want the visibilty true.

Thanks in advance,
Dan

Why dont you use a IF THEN STATEMENT

Code:
Dim currentDate As Date
currentDate = Now

Dim date1 As Date
Dim date2 As Date
date1 = DateAdd("d", -25, currentDate)
date2 = DateAdd("d", 5, currentDate)

If Me.Next_Payment_Due >= date1 And Me.Next_Payment_Due <= date2 Then
pds.Visible = True
Else
pds.Visible = False
End If
 
Or, since the visible property is a boolean and the expression you are evaluating is also a boolean, therefore they vary directly and you don't even need an if statement. The visibility is equal to the expression...
Code:
pds.visible = _
  Me.Next_Payment_Due >= DateAdd("d", -25, Date) _
  AND _
  Me.Next_Payment_Due <= DateAdd("d", 5, Date)
 
Or, since the visible property is a boolean and the expression you are evaluating is also a boolean, therefore they vary directly and you don't even need an if statement. The visibility is equal to the expression...
Code:
pds.visible = _
  Me.Next_Payment_Due >= DateAdd("d", -25, Date) _
  AND _
  Me.Next_Payment_Due <= DateAdd("d", 5, Date)

Nice alternative. :) I have never done it that way.
 

Users who are viewing this thread

Back
Top Bottom