Results 1 to 9 of 9
  1. #1
    fluppe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    48

    How to add functionality to project

    Hi,

    i have the following question:
    I want to add a method/Function to my project that can be shared by all the Callbacks that i write.
    How can i add such a function/method to the Application-object for example ?
    ... or any other way ...

    My function will need some arguments, just for information.

    Thanks for reading this post, any help would be great.



    Yours,
    ...

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I dont know what a callback it, but to write a function
    ctl-G (to get to VBE, visual basic editor)
    ctl-R (to see your project objects)
    from the menu: INSERT, MODULE
    in this new mdule , from the menu: INSERT, PROCEDURE
    the add procedure dialog appears: Enter the name of the function
    click the FUNCTION option
    and PUBLIC option
    click OK

    put your arguments in the command line..example:
    and assign the value to the function name.
    Code:
    public function calcCircumference( byval pvRadius)
    calcCircumference = 2 * 3.141 * pvRadius
    end function
    Then in the query put the field name calcCircumference([radius]) as Circ.

  3. #3
    fluppe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    48
    Well,
    thanks for your answer ...
    by "Callback" i mean all those methodes one gets by using the "Event" pane of the properties-section (in the design-view) of a form. What happens when "Click" and "open" and all that ...

    At least these are methods, but they are attached to the Form automatically and i do not know how achieve that without the "properties pane".


    I'll try that with the function ... Thanks a lot,

    ...

  4. #4
    fluppe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    48
    Hello,

    back from trying ... it seems that the whole problem is that my "function call" doesn't work. It wants return values ... no matter if i try as a "sub" or as "function".
    I don't know what the problem is about that. If i declare a "Sub"(function), it should not have a return value, right ?
    Code:
    exfcn(name_src, name_tar, num, fields, fields_tar)
    is red from the beginning,
    Code:
    flag = exfcn(name_src, name_tar, num, fields, fields_tar)
    is OK (syntax seems to be at last)

    However, i don't know, any idea ?

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Can you describe what you are trying to achieve in a few sentences-- no database jargon?

    Does this link help? http://office.microsoft.com/en-ca/ac...005186744.aspx

  6. #6
    fluppe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    48
    Oh,

    well ... i will describe as good as i can:

    I want to add a VBA Function to my access project that can be then called from various Procedures that are executed when the User presses buttons etc.. The functionality can be shared.
    So I added a Module (as described) and added a Procedure (as described by ranman256 as well) ... but when I choose SUB and not FUNCTION, it doesn't work.
    I CANNOT CALL THE PROCEDURE. I'm told very politely that an output arg is missing. I just don't understand that.

    If I choose FUNCTION it works when i declare some output however, but it should work as well with choosing SUB and no outputs, or ?

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Please post the code. A Function returns a value. SUB does not. Sub and Function can each have input parameters.

    Do you have an example of the functionality you're talking about? Change color of label/caption..

    Ranman's function is incorrect. It should have an output parameter.

    for example
    public function calcCircumference( byval pvRadius) as Long
    calcCircumference = 2 * 3.141 * pvRadius
    end function

  8. #8
    fluppe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    48
    Hello,
    I'm sorry but i am currently not having the code with me, so it's just a summary, but it is all the relevant stuff i'm sure.The code in the Function and the Sub is the same, except the Return statement.

    Ok, it all looks like ... say "pb_one" is the name of a Pushbutton in a form of my project ...

    I added a Module "MyMod" and there i added a "Sub"
    Code:
    Public Sub somefunc(ind As Integer, str As String)
    
    Dim var As String
    
    ...
    ' Do s.th. with SQL and stuff
    ...
    ' And do not return anything
    
    End Sub
    In the "autogenerated" Procedure "pb_one_click", it looks like

    Code:
    Public Sub pb_one_click()
    
    
    ...
    ' s.th. as above
    ....
    
    somefunc(ind, str)
    
    
    End Sub
    That does not work however ...

    If I do declare "somefunc" as
    Code:
    Public Function somefunc(ind As Integer, str As String) As Boolean
    
    
    
    Return True  ' f. ex.
    
    End Function
    (and call it ... ) it works fine.

    That is my problem...,and i don't know where it arises from.

    So, thanks for your help so far, maybe this gives a better insight to my problem.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 07-16-2014, 12:51 PM
  2. Implementing Calender Functionality with Outlook
    By Dclassen89 in forum Access
    Replies: 1
    Last Post: 02-06-2014, 09:55 AM
  3. Search functionality in form
    By baendres in forum Reports
    Replies: 2
    Last Post: 11-04-2013, 06:45 PM
  4. Semi-colon Functionality
    By TheDeceived in forum Access
    Replies: 3
    Last Post: 09-22-2010, 10:52 AM
  5. Replies: 0
    Last Post: 06-29-2010, 07:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums