call VBA function in access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkshansid
    New Member
    • Oct 2008
    • 232

    #1

    call VBA function in access

    Kindly help me how to write and call VBA function in access
    I want to print simple hi function with VBA programming
    VBA function is not working correctly and asks for parameter value and after giving any rough value such as a then print #name?
    I write the function by clicking view code
    Code:
    Sub hum()
    prn.Text = "hi"
    End Sub
    On textbox with name prn I write
    =hum()
    But a popup box opens and ask for Enter parameter value
    Kindly help
    Thanks in advance
    Last edited by kkshansid; May 2 '12, 11:40 AM. Reason: error
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    prn is not defined.

    Please read Before Posting (VBA or SQL) Code. I expect it may help you.

    Comment

    • Mihail
      Contributor
      • Apr 2011
      • 759

      #3
      While I am not sure what you are looking for I can't be sure that this is a good answer:

      Use a Function, not a Subroutine;
      Put this function in a regular module (not a form or a report module).
      Declare the function as Public:
      Code:
      Public Function Hum() As String
          'Set the returning value
          Hum =  "hi"
      End Sub
      Now, use the function in your text box: = Hum()

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Allthough not directly related to the errors in your code, I think you may find the following link usefull:


        It explains how to write and use a function from within access VBE, and shows a few ways of calling said function from your form/query/code.

        Comment

        • Mihail
          Contributor
          • Apr 2011
          • 759

          #5
          Good work Smiley!
          If you can add an example about how to use this in a report too I think will be fully complete.

          For now I wish to inform kkshansid that the technique for reports is exactly the same with the technique for forms.

          Comment

          Working...