I have a form that uses a pick list to select a specified date/time range based on the case value. Case 1-7 have pre-defined date/time functions, but case 8 is for a custom date/time range. I only want to show the custom fields when the custom date range option is selected. When the form loads I have all the fields hidden.
[code=vb]Private Sub Form_Load()
Me!CustomDateBo x.Visible = False
Me!dtpStartDate .Value = Date
Me!dtpEndDate.V alue = Date
Me!dtpStartDate .Visible = False
Me!cstStartTime .Visible = False
Me!dtpEndDate.V isible = False
Me!cstEndTime.V isible = False
Me!lblCstDateRa nge.Visible = False
Me!lblFrom.Visi ble = False
Me!lblTo.Visibl e = False
End Sub
[/code]
When case "8" is selected the same fields are set to true and the fields are visible and all works well. What I want to try and accomplish is a cleaner way in my code to hide these fields whenever one of the other options is reselected.
I have placed the above code in each case statement and that works, but it seams to me that I should be able to simly make an If-Then-Else type statement so that I only have to enter the code 1 time.
I have tried several variations of the following but I get syntax errors or compile errors.
Any thoughts?
[code=vb]DateSelectorVal ue = Me!DateSelector
Select Case DateSelectorVal ue
If DateSelectorVal ue Is = 8 Then
Me!CustomDateBo x.Visible = True
Me!dtpStartDate .Visible = True
Me!cstStartTime .Visible = True
Me!dtpEndDate.V isible = True
Me!cstEndTime.V isible = True
Me!lblCstDateRa nge.Visible = True
Me!lblFrom.Visi ble = True
Me!lblTo.Visibl e = True
Else
Me!CustomDateBo x.Visible = False
Me!dtpStartDate .Visible = False
Me!cstStartTime .Visible = False
Me!dtpEndDate.V isible = False
Me!cstEndTime.V isible = False
Me!lblCstDateRa nge.Visible = False
Me!lblFrom.Visi ble = False
Me!lblTo.Visibl e = False
End If
Case "1" 'Today
Me!START = DateString(Now( )) & "000000"
Me!END = DateString(Now( )) & "235959"
Me!END2 = DateString(Date + 1) & "013000"
Case "2" 'Yesterday
Me!START = DateString(Date - 1) & "000000"
Me!END = DateString(Date - 1) & "235959"
Me!END2 = DateString(Date ) & "013000"
Case "3" 'Week-To-Date
Me!START = DateString(Date - Weekday(Date) + 1) & "000000"
Me!END = DateString(Date ) & "235959"
Me!END2 = DateString(Date + 1) & "013000"
Case "4" 'Last Week
Me!START = DateString(Date - Weekday(Date) - 6) & "000000"
Me!END = DateString(Date - Weekday(Date) - 7 + 7) & "235959"
Me!END2 = DateString(Date - Weekday(Date) - 7 + 8) & "013000"
Case "5" 'Month-To-Date
Me!START = DateString(Date Serial(YEAR(Dat e), MONTH(Date), 1)) & "000000"
Me!END = DateString(Date ) & "235959"
Me!END2 = DateString(Date + 1) & "013000"
Case "6" 'Last Month
Me!START = DateString(Date Serial(YEAR(Dat e), MONTH(Date) - 1, 1)) & "000000"
Me!END = DateString(Date Serial(YEAR(Dat e), MONTH(Date), 0)) & "235959"
Me!END2 = DateString(Date Serial(YEAR(Dat e), MONTH(Date), 1)) & "013000"
Case "7" 'Last 20 Weeks
Me!START = DateString(([L20W]) - Weekday([L20W]) + 1) & "000000"
Me!END = DateString(Date - Weekday(Date) - 7 + 7) & "235959"
Me!END2 = DateString(Date - Weekday(Date) - 7 + 8) & "013000"
Case "8" 'Custom
Me!START = DateString([dtpStartDate]) & TimeString([cstStartTime])
Me!END = DateString([dtpEndDate]) & TimeString([cstEndTime])
Me!END2 = GetDateString([cEND2])
End Select
End Sub
[/code]
[code=vb]Private Sub Form_Load()
Me!CustomDateBo x.Visible = False
Me!dtpStartDate .Value = Date
Me!dtpEndDate.V alue = Date
Me!dtpStartDate .Visible = False
Me!cstStartTime .Visible = False
Me!dtpEndDate.V isible = False
Me!cstEndTime.V isible = False
Me!lblCstDateRa nge.Visible = False
Me!lblFrom.Visi ble = False
Me!lblTo.Visibl e = False
End Sub
[/code]
When case "8" is selected the same fields are set to true and the fields are visible and all works well. What I want to try and accomplish is a cleaner way in my code to hide these fields whenever one of the other options is reselected.
I have placed the above code in each case statement and that works, but it seams to me that I should be able to simly make an If-Then-Else type statement so that I only have to enter the code 1 time.
I have tried several variations of the following but I get syntax errors or compile errors.
Any thoughts?
[code=vb]DateSelectorVal ue = Me!DateSelector
Select Case DateSelectorVal ue
If DateSelectorVal ue Is = 8 Then
Me!CustomDateBo x.Visible = True
Me!dtpStartDate .Visible = True
Me!cstStartTime .Visible = True
Me!dtpEndDate.V isible = True
Me!cstEndTime.V isible = True
Me!lblCstDateRa nge.Visible = True
Me!lblFrom.Visi ble = True
Me!lblTo.Visibl e = True
Else
Me!CustomDateBo x.Visible = False
Me!dtpStartDate .Visible = False
Me!cstStartTime .Visible = False
Me!dtpEndDate.V isible = False
Me!cstEndTime.V isible = False
Me!lblCstDateRa nge.Visible = False
Me!lblFrom.Visi ble = False
Me!lblTo.Visibl e = False
End If
Case "1" 'Today
Me!START = DateString(Now( )) & "000000"
Me!END = DateString(Now( )) & "235959"
Me!END2 = DateString(Date + 1) & "013000"
Case "2" 'Yesterday
Me!START = DateString(Date - 1) & "000000"
Me!END = DateString(Date - 1) & "235959"
Me!END2 = DateString(Date ) & "013000"
Case "3" 'Week-To-Date
Me!START = DateString(Date - Weekday(Date) + 1) & "000000"
Me!END = DateString(Date ) & "235959"
Me!END2 = DateString(Date + 1) & "013000"
Case "4" 'Last Week
Me!START = DateString(Date - Weekday(Date) - 6) & "000000"
Me!END = DateString(Date - Weekday(Date) - 7 + 7) & "235959"
Me!END2 = DateString(Date - Weekday(Date) - 7 + 8) & "013000"
Case "5" 'Month-To-Date
Me!START = DateString(Date Serial(YEAR(Dat e), MONTH(Date), 1)) & "000000"
Me!END = DateString(Date ) & "235959"
Me!END2 = DateString(Date + 1) & "013000"
Case "6" 'Last Month
Me!START = DateString(Date Serial(YEAR(Dat e), MONTH(Date) - 1, 1)) & "000000"
Me!END = DateString(Date Serial(YEAR(Dat e), MONTH(Date), 0)) & "235959"
Me!END2 = DateString(Date Serial(YEAR(Dat e), MONTH(Date), 1)) & "013000"
Case "7" 'Last 20 Weeks
Me!START = DateString(([L20W]) - Weekday([L20W]) + 1) & "000000"
Me!END = DateString(Date - Weekday(Date) - 7 + 7) & "235959"
Me!END2 = DateString(Date - Weekday(Date) - 7 + 8) & "013000"
Case "8" 'Custom
Me!START = DateString([dtpStartDate]) & TimeString([cstStartTime])
Me!END = DateString([dtpEndDate]) & TimeString([cstEndTime])
Me!END2 = GetDateString([cEND2])
End Select
End Sub
[/code]
Comment