1

I am new to access I would like to use a UDF in my SELECT sql statement like this:

select birthdate,GoMonth(birthdate,12) as yearold from data

The above statement will give a field name yearold 12 months after birthdate


function GoMonth(pDate,num) as datetime
    GoMonth=DateAdd("m",num,pdate)
end function

I don't know where to put or write the function
I am working with other databases and don't want to change my sql statements for each of them.

2
  • are you using Access as a frontend aswell or just as a database? Commented Aug 3, 2011 at 10:24
  • 1
    Why do you need a user-defined function? In your example, you can just use the DateAdd() function directly. Or have you just used a bad example that implies things that don't apply to your real situation? Commented Aug 3, 2011 at 20:51

1 Answer 1

3

If you use Access as a frontend, put it in a module and make it a public function(). If you have another frontend, then you can't use user-defined functions with a MS Access database, as the functions are interpreted by Access and not the JET driver.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.