I have a function tha I have written which I am trying to run from a macro using Runcode. The macro that I am trying to call the function from is the OnClick event of a command button. Basically, I want to print a different page of my reort dependent upon the value in the text control "Text28." But when I press the button, the code is function is not running and I can't figure out why. Any suggestions would be very much appreciated! Here is what I have for the function: -
Public Function PrintOut()
-
If Text28 = "aaa" Then
-
DoCmd.PrintOut acPages, 2, 2, , 1
-
ElseIf Text28 = "bbb" Then
-
DoCmd.PrintOut acPages, 3, 3, , 1
-
ElseIf Text28 = "ccc" Then
-
DoCmd.PrintOut acPages, 4, 4, , 1
-
ElseIf Text28 = "ddd" Then
-
DoCmd.PrintOut acPages, 5, 5, , 1
-
End If
-
End Function
Try: - Public Function PrintOut(strTest As String)
-
Select Case strTest
-
Case "aaa"
-
DoCmd.PrintOut acPages, 2, 2, , 1
-
Case "bbb"
-
DoCmd.PrintOut acPages, 3, 3, , 1
-
Case "ccc"
-
DoCmd.PrintOut acPages, 4, 4, , 1
-
Case "ddd"
-
DoCmd.PrintOut acPages, 5, 5, , 1
-
Case Else
-
End Select
-
End Function
Then on the OnClick() event of your button, use this code: 5 1625
I noticed that the function you posted is public. Is it in a separate module than the form that has the command button?
If so, you will need to pass an argument to the function, in this case the value of Text28. Depending on your answer, I have some suggestion to make your code more efficient.
Yes it is in a separate module
Try: - Public Function PrintOut(strTest As String)
-
Select Case strTest
-
Case "aaa"
-
DoCmd.PrintOut acPages, 2, 2, , 1
-
Case "bbb"
-
DoCmd.PrintOut acPages, 3, 3, , 1
-
Case "ccc"
-
DoCmd.PrintOut acPages, 4, 4, , 1
-
Case "ddd"
-
DoCmd.PrintOut acPages, 5, 5, , 1
-
Case Else
-
End Select
-
End Function
Then on the OnClick() event of your button, use this code:
Thank you so much for your help
You're very welcome, happy to help.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lucy Randles |
last post by:
I've written a VBA function that I then need to call in a form.
Previously to do this I have written the call procedure in the same
module as the function - i.e. Function callfunctionname()
Call...
|
by: PawelR |
last post by:
Hello Group,
In my application I have few class, and I want call function with "master
class". This is as master form (startClass) and option window (ClassA). My
question is how call function...
|
by: Dave |
last post by:
I have a program that I've written a class for. I need to call the function
in the program from the class. When I try to call the function I receive the
error, the name xxx does not exist in the...
|
by: moondaddy |
last post by:
I'm using vb.net and have an aspx page where I want to call a function in
the code behind to do something on the backend and I want to call this
function from a jscript function in the aspx page. ...
|
by: Tiraman |
last post by:
Hi ,
I have 3 files ,
middle.aspx file include the header.aspx and footer.aspx files .
in each of the include files there is a function and from some reason the
call to the Footer() function...
|
by: leaf |
last post by:
Hi,
How to call function at runtime,
based on a struct that contains the information for the function call:
struct func_to_call {
int function_id; // function id to call
unsigned int nparams;...
|
by: yaru22 |
last post by:
Hi. I'm wondering if there is a way to call function that a variable
refers to.
I was writing a script to load xml file.
And what I've written so far looks like this:
var xmlDoc;
...
|
by: Khai Doan |
last post by:
I have function A, which need to call function B with the exact same
argument list. What is the correct way to do this?
I had function A:
function A {
B(arguments);
}
but it does not...
|
by: slickdock |
last post by:
My vb code saves a record as a Word merge data file and merges it with
a Word merge form file. Once the merge is complete, I would like the
code to make this determination:
There will always be...
|
by: intermanch |
last post by:
how call function php($varible) into javascript withod ajax:
<!--
this code only call funnctions php but
how call function php
intermanch@gmail.com
www.intermanch.blogfa.com
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |