A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

User-Defined Functions in MS Access?



 
 
Thread Tools Display Modes
  #1  
Old June 3rd, 2004, 09:39 AM
yisraelharris
external usenet poster
 
Posts: n/a
Default User-Defined Functions in MS Access?


I am building a query, and besides various table columns, I need it to
output a string whose value depends on a non-straightforward algorithm
based on the values of other columns.

If I were in SQL-Server, I would simply write and invoke a user-defined
function. In MS Access, what does one do?

As I am a relative novice in MS Access, I would be grateful for
solutions which spell things out explicitly. Thank you.


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #2  
Old June 4th, 2004, 06:38 AM
John Vinson
external usenet poster
 
Posts: n/a
Default User-Defined Functions in MS Access?

On Thu, 3 Jun 2004 03:39:32 -0500, yisraelharris
wrote:


I am building a query, and besides various table columns, I need it to
output a string whose value depends on a non-straightforward algorithm
based on the values of other columns.

If I were in SQL-Server, I would simply write and invoke a user-defined
function. In MS Access, what does one do?

As I am a relative novice in MS Access, I would be grateful for
solutions which spell things out explicitly. Thank you.


On the Modules tab on the database window, create a new Module. You
can write a function in VBA - the syntax is different than T-SQL but
if you're familiar with Visual Basic, it's just another dialect.
Specify

Public Function MyFunctionName(arg1 AS Variant, arg2 AS Variant) As
Variant
your expressions here
MyFunctionName = the final result of your algorithm
End Function

In the Query you can then type

FuncResult: MyFunctionName(thisfield, thatfield)

to perform the calculation.

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:39 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.