Returning a Select Case statement value

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
 
M

Michael Hopwood

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).
 
T

TC

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)
 
G

George Nicholson

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,
 

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