Returning a Select Case statement value

  • Thread starter Thread starter JJR
  • Start date Start date
J

JJR

I have a simple select case statement that I want to return a value to a
table I
call Players. I evaluate a date range from the field DATE_OF_BI and I want
to have the FindGroup field to be passed the result. The code runs but no
value to returned the field FindGroup. What am i doing wrong.
Thanks for any help. Code is as follows:

Option Compare Database

Function GetGroup() As String
Select Case DATE_OF_BI
Case #8/1/1989# To #7/31/1990#
FindGroup = "U15"
Case #8/1/1990# To #7/31/1991#
FindGroup = "U14"
Case Else
FindGroup = "Check DOB"
End Select

End Function
 
Function GetGroup(Dt as Date) As String
Select Case Dt
Case #8/1/1989# To #7/31/1990#
GetGroup = "U15"
Case #8/1/1990# To #7/31/1991#
GetGroup = "U14"
Case Else
GetGroup = "Check DOB"
End Select
End Function


I think you are misunderstanding the way that functions work, you have to
pass a value to the function in this situation (Dt) and assign the value you
want to the function name (GetGroup) once you have calculated it.

You can use this function in a query but not in a table, it's better to
calculate values than to store them (generally speaking).
 
Note how Michael has spaced-out your statement. Your code will be way easier
for you & anyone else to follow, if you space your code out properly.

HTH,
TC


(snip)
 
If you had set Option Explicit (right after Option Compare Database), when
you tried to compile or run your code the debugger would have pointed out to
you that FindGroup was an undefined variable. At that point you probably
would have realized that you meant to use GetGroup instead (or vice versa).

Easy mistake to make, easy to catch if you let the VBE look over your
shoulder.

Hope this helps,
 
Back
Top