Option Group Coding

G

Guest

I'm trying to code an "option group" and I have run into a problem.

My option group has 3 selections (short, medium, long) where the "short"
option is 90 days or less, the "medium" option is 91 to 180 days, and the
"long" option is 181 days to 365 days. At first I thought I could write it
with a "Select Case" statement but now I think it will require a really long
and nasty "IF" statement instead. My VB6 book is at my office whereas I'm
stuck at home with a severe cold/flu.

I have a "starting date" and a "ending date" for projects, what I'm looking
for is when the user inputs the starting date and the ending date into my
form, then they go to the 'Project Term Length" option group and select
either "short", "medium" or "long" term. Based on the amount of days between
"start" and "ending", when the user selects an option, and if they pick the
wrong one for the amount of days, they get a message stating to select
another option or to select the "correct" option for the amount of days
projected.

Here is the "Case Select" code that I started writing and then decided that
I might should use an "IF, Then" statement instead:
Private Sub ProjectLength_AfterUpdate()
Dim intSelect As Integer
Dim Msg As String
Dim strName As String

Select Case ProjectLength
Case Is = 1
intSelect = 1
If (Me![Date_End] - Me![Date_Start] <= 90) Then
strName = "Short Term"
Else
Case Is = 2
intSelect = 2
If (Me![Date_End] - Me![Date_Start] <= 180) Then
strName = "Medium Term"
Else
Case Is = 3
intSelect = 3
If (Me![Date_End] - Me![Date_Start] > 180) Then
strName = "Long Term"
End If
End Select
End Sub

I would really appreciate if someone could give me an idea as to how to code
this properly.

Thanks
 
G

Guest

Why don't you calculate the term for the user based on the "starting date"
and a "ending date"? if you do this your function will look like:

Function Project_Term(ByVal StartDate, _
ByVal FinishDate) As String
Dim Result As String
Dim DaysInRange As Long

DaysInRange = FinishDate - StartDate
Result = ""
Select Case DaysInRange
Case 0 To 90: Result = "Short Term"
Case 91 To 180: Result = "Medium Term"
Case Is >= 181: Result = "Long Term"
End Select

Project_Term = Result
End Function
 
D

DubboPete

Bobby,

if you have a startdate and enddate, then surely you can get the calculated
difference, then set your option group accordingly, so the user doesn't have
to second-guess what the date difference is?

does that help?

DubboPete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top