»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 11-15-2003, 09:30 PM   #1 (permalink)
Registered User
 
NoLimit's Avatar
 
Join Date: Apr 2001
Location: Northern California, USA
Posts: 55
NoLimit is on a distinguished road
need help with a vb function for ms access

I'm trying to write a function that would examine a date from a table and if it's between a certain range, it will output a string of characters. The problem is I'm getting a blank spot for some dates instead of a string of characters. Here's what I got so far:

Public Function Aged(datIn As Date) As String

Dim strAged As String

If datIn < Date - 120 Then
strAged = "121 and over "

ElseIf (datIn <= Date - 120) Then
strAge = " 91-120"

ElseIf (datIn <= Date - 90) Then
strAge = " 61-90"

ElseIf (datIn <= Date - 60) Then
strAge = " 31-60"

ElseIf (datIn <= Date - 30) Then
strAge = " 1-30"

ElseIf datIn = Date Then
strAge = "today"

End If
Aged = strAge
End Function

NoLimit is offline   Reply With Quote
Old 11-16-2003, 12:07 AM   #2 (permalink)
Registered User
 
Join Date: Sep 2002
Posts: 265
Creosote is on a distinguished road
Well you don't have a default value. Its easier to do this type of stuff with a select case IMO. Try the following:

Code:
Public Function Aged(DateIn As Date) As String
    Dim Age As String
    Select Case -1 * (DateDiff("d", Date, DateIn))
        Case Is > 120
            Age = "121 and over"
        Case 91 To 120
            Age = "91 to 120"
        Case 61 To 90
            Age = "61 to 90"
        Case 31 To 60
            Age = "31 to 60"
        Case 1 To 30
            Age = "1 to 30"
        Case 0
            Age = "Today"
        Case Else
            Age = "Unknown"
    End Select
    Aged = Age
End Function
Creosote is offline   Reply With Quote
Old 11-16-2003, 12:44 AM   #3 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
"Case Is > 120
Age = "121 and over"

Case Is? lol
Not sure what language that is

You only have it on one line though

If you want, you could do like creosote has and put
Age = "Unknown " & datIn

so you can see what the value is thats getting through
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Old 11-16-2003, 11:48 AM   #4 (permalink)
Registered User
 
Join Date: Sep 2002
Posts: 265
Creosote is on a distinguished road
Quote:
Case Is? lol
Not sure what language that is
The language would be called VB...lol
Creosote is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 03:42 PM.