Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 4th, 2005, 07:35 AM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calling User Defined Function

Hi experts !
I've a user defined function that runs ok when called from a sub
procedure through the imediate window.I would like to call the
function from a button on a form. Which code i need on the OnClick
properties window of the button ?
Any help will be welcome.
Regards Penta.

  #2 (permalink)  
Old March 4th, 2005, 07:46 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Penta,

If your UDF is like this in a module

Function MyFunction() as string
    'Function Code
End Function

Then you can just type it directly into the sub -

Private sub Button1_OnClick()
    txtBox = MyFunction
end sub

If your Function takes arguments

Function MyFunction(arg1 as string, arg2 as integer, arg3 as boolean) as string
    'Function Code
End Function

then -

Private sub Button1_OnClick()
    txtBox = MyFunction (Argument1, Argument2, etc.)
end sub

Does this help?

Jon
  #3 (permalink)  
Old March 4th, 2005, 07:48 AM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jon !
Thank u for ur explanation. I'm going to try.
R.P.

  #4 (permalink)  
Old March 4th, 2005, 10:03 AM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jon !
I must be doing something wrong because i've been having error messages.
On ur explanation i dont know where txtBox comes from. Could u be more
explicit please ?
Thanks again.
R.P.

  #5 (permalink)  
Old March 4th, 2005, 10:34 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

For what its worth, this took me a while to get.

If you call a function, and it has no return value, what you would do, is just call the function with the arguments behind, but not assign it to any variable, and leave out the parentheses.

e.g.
MyFunction var1
This would run MyFunction and then just continue with the next line in your code.

If your function returns a value, you want to assign the return value to a variable and bracket the variables.

e.g.
var2 = MyFunction(var1)
This runs MyFunctions and assigns the return value to var2.

It looks as though this is what Jon was trying to do with txtBox, just assign it the return value of the function.

Hope that helps,

Mike


Mike
EchoVue.com
  #6 (permalink)  
Old March 4th, 2005, 12:57 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Penta, when Mike used "txtBox" in his code, he didn't mean for you to literally use that for your code. He really means user YOUR control in its place. So if you have a control that's called, for example, Project, then use

Project = MyFunction()

If you have a control that's called Status, then use

Status = MyFunction()

txtBox is just a fake name he used for an example. Use your real name instead.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Defined function in XSL1.0 elayaraja.s XML 1 July 22nd, 2008 03:24 AM
Go for View or User Defined function vinod_yadav1919 SQL Server 2000 1 December 12th, 2007 05:18 AM
calling the user defined function on click event CsharpHelp C# 1 June 6th, 2005 07:25 AM
User Defined Function niravp SQL Server 2000 7 November 29th, 2004 02:18 PM
Using a user defined type and the Split Function nikotromus Access VBA 2 August 20th, 2004 12:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.