By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,762 Members | 1,836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,762 IT Pros & Developers. It's quick & easy.

call VBA function in access

P: 232
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
Expand|Select|Wrap|Line Numbers
  1. Sub hum()
  2. prn.Text = "hi"
  3. End Sub
On textbox with name prn I write
But a popup box opens and ask for Enter parameter value
Kindly help
Thanks in advance
May 2 '12 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 15k+
P: 31,489
prn is not defined.

Please read Before Posting (VBA or SQL) Code. I expect it may help you.
May 2 '12 #2

P: 759
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:
Expand|Select|Wrap|Line Numbers
  1. Public Function Hum() As String
  2.     'Set the returning value
  3.     Hum =  "hi"
  4. End Sub
Now, use the function in your text box: = Hum()
May 3 '12 #3

Expert Mod 100+
P: 2,321
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.
May 3 '12 #4

P: 759
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.
May 3 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.