select case?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a column(E) that should calculate a date depending on the values of
other columns. Column A can contain one of three potential values. If value
1 is entered, column E is today's date +5. If value 2 is entered, column E
is todays date +15. If value 3 is entered, column E is todays date +30.
However, if column B contains a date, that date overrides the values in
column A and is entered in column E. I think this should be done with a
select case, but am not certain how to do it.
Would appreciate any help.
 
Yes, it could be done in code with a Select Case. It could also be done as a
calculated control on a form or report (i.e. place the calculation in the
Control Source of the control).

Example (in code):
If Not IsDate(Me!B) Then
Select Case Me!A
Case 1
Me!E = Date + 5
Case 2
Me!E = Date + 15
Case 3
Me!E = Date + 30
Case Else
Msgbox "Error in Select Case statement!"
End Select
Else
Me!E = Me!B
End If

Example (Control Source):
=IIf(IsDate(), , Choose([A], Date()+5, Date()+15, Date()+30))
 
Thank you, Wayne! I'm gonna give it a shot.

Wayne Morgan said:
Yes, it could be done in code with a Select Case. It could also be done as a
calculated control on a form or report (i.e. place the calculation in the
Control Source of the control).

Example (in code):
If Not IsDate(Me!B) Then
Select Case Me!A
Case 1
Me!E = Date + 5
Case 2
Me!E = Date + 15
Case 3
Me!E = Date + 30
Case Else
Msgbox "Error in Select Case statement!"
End Select
Else
Me!E = Me!B
End If

Example (Control Source):
=IIf(IsDate(), , Choose([A], Date()+5, Date()+15, Date()+30))

--
Wayne Morgan
MS Access MVP


kwinbo said:
I have a column(E) that should calculate a date depending on the values of
other columns. Column A can contain one of three potential values. If
value
1 is entered, column E is today's date +5. If value 2 is entered, column
E
is todays date +15. If value 3 is entered, column E is todays date +30.
However, if column B contains a date, that date overrides the values in
column A and is entered in column E. I think this should be done with a
select case, but am not certain how to do it.
Would appreciate any help.
 
Back
Top