Does MS Access 2007 support creation of user defined sql functions? if so, where is the option for it in the menu?
A:
You can create custom functions using VBA Module Functions.
Have a look at Build Custom Functions for Your Access Applications
astander
2009-12-13 10:58:55
butyou can't have real sql functions, right?
Haim Bender
2009-12-15 09:47:12
You can create *VBA functions*, that you can use in you *MS Access Queries*.
astander
2009-12-15 09:52:44
@Haim Bender: what's a "real SQL function"?
David-W-Fenton
2009-12-15 23:54:18
@David W. Fenton: "what's a 'real SQL function'" -- presumably one that can be defined using Standard SQL/PSM CREATE FUNCTION (e.g. http://www.postgres.cz/index.php/SQL/PSM_Manual) or similar proprietary SQL syntax (e.g. http://msdn.microsoft.com/en-us/library/ms186755.aspx).
onedaywhen
2009-12-16 11:02:52
A:
queries can take parameters which makes them similar to stored procedures. Functions can be achieved through VBA.
Paul Creasey
2009-12-13 11:01:06
+1
A:
If you mean can you use User Defined Functions (UDF) in SQL in Access, yes you can. For example, if you wanted the median value, you might write SQL in the query design window like so:
SELECT s.Month,
Sum(([SentTo])) AS [Sum Sent],
fMedian("Statistics","Month",[Month],"SentTo") AS [Median Sent]
FROM Statistics s
GROUP BY s.Month
Where fMedian refers to code in a module:
Function fMedian(SQLOrTable, GroupFieldName, GroupFieldValue, MedianFieldName)
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs1 = db.OpenRecordset(SQLOrTable, dbOpenDynaset)
If IsDate(GroupFieldValue) Then
GroupFieldValue = "#" & GroupFieldValue & "#"
ElseIf Not IsNumeric(GroupFieldValue) Then
GroupFieldValue = "'" & Replace(GroupFieldValue, "'", "''") & "'"
End If
rs1.Filter = GroupFieldName & "=" & GroupFieldValue
rs1.Sort = MedianFieldName
Set rs = rs1.OpenRecordset()
rs.Move (rs.RecordCount / 2)
If rs.RecordCount Mod 2 = 0 Then
varMedian1 = rs.Fields(MedianFieldName)
rs.MoveNext
fMedian = (varMedian1 + rs.Fields(MedianFieldName)) / 2
Else
fMedian = rs.Fields(MedianFieldName)
End If
End Function
From: http://wiki.lessthandot.com/index.php/Aggregate%5FMedian%5F%28UDF)
Remou
2009-12-13 13:07:34