By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,139 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,139 IT Pros & Developers. It's quick & easy.

Syntax Error in Simple SQL Statement?

P: 1
Hi there!

I'm trying to group employees into age groups to see percentages per age group. This is my code:

Expand|Select|Wrap|Line Numbers
  1. SELECT [CSH Employees].DOB, [CSH Employees].status
  2. FROM [CSH Employees]
  3. WHERE (([CSH Employees].status)<>"former")
  4.  
  5. Public Function AgeGroup(DOB As Date) As String
  6.  
  7.     Dim intAge As Integer
  8.  
  9.     'Age Calculation
  10.     intAge = DateDiff("yyyy", [DOB], Now()) + _
  11.              Int(Format(Now(), "mmdd") < Format([DOB], "mmdd"))
  12.  
  13.     Select Case intAge
  14.  
  15.         'For each Age range, write out Age Group (used in qry)
  16.     CaseIs < 30
  17.         AgeGroup = "<30"
  18.     Case 30 to 44
  19.         AgeGroup = "30-44"
  20.     Case 45 to 59
  21.         AgeGroup = "45-59"
  22.     Case Is > 59
  23.         AgeGroup = "60+"
  24.      End Select
  25.  
  26. End Function
I'm getting this error:

Syntax error (missing operator) in query expression '(([CSH Employees].status)<>"former")
Public Function AgeGroup(DOB As Date) As String
Dim intAge As Integer
'Age Calculation
intAge = DateDiff("yyyy", [DOB], Now()) + _
Int(Format(Now(), "mmdd") < Format([DOB], "mmdd"))

What am I missing or doing wrong?
Jun 21 '12 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,357
Please use code tags when posting code.

Did you try to use VBA code in SQL? You can't do that. the VBA code needs to go in a module and then you call it from a SQL query. Also, no where in your SQL do you call the function you define.
Jun 21 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.