473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Call function from macro using RunCode

20
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:
Expand|Select|Wrap|Line Numbers
  1. Public Function PrintOut()
  2.     If Text28 = "aaa" Then
  3.         DoCmd.PrintOut acPages, 2, 2, , 1
  4.     ElseIf Text28 = "bbb" Then
  5.         DoCmd.PrintOut acPages, 3, 3, , 1
  6.     ElseIf Text28 = "ccc" Then
  7.         DoCmd.PrintOut acPages, 4, 4, , 1
  8.     ElseIf Text28 = "ddd" Then
  9.         DoCmd.PrintOut acPages, 5, 5, , 1
  10. End If
  11. End Function
Aug 7 '19 #1

✓ answered by Nauticalgent

Try:
Expand|Select|Wrap|Line Numbers
  1. Public Function PrintOut(strTest As String)
  2.     Select Case strTest
  3.         Case "aaa"
  4.             DoCmd.PrintOut acPages, 2, 2, , 1
  5.         Case "bbb"
  6.             DoCmd.PrintOut acPages, 3, 3, , 1
  7.         Case "ccc"
  8.             DoCmd.PrintOut acPages, 4, 4, , 1
  9.         Case "ddd"
  10.             DoCmd.PrintOut acPages, 5, 5, , 1
  11.         Case Else
  12.     End Select
  13. End Function
Then on the OnClick() event of your button, use this code:
Expand|Select|Wrap|Line Numbers
  1. Call PrintOut(Me.Text28)
  2.  

5 1625
Nauticalgent
100 64KB
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.
Aug 11 '19 #2
kledki
20
Yes it is in a separate module
Aug 13 '19 #3
Nauticalgent
100 64KB
Try:
Expand|Select|Wrap|Line Numbers
  1. Public Function PrintOut(strTest As String)
  2.     Select Case strTest
  3.         Case "aaa"
  4.             DoCmd.PrintOut acPages, 2, 2, , 1
  5.         Case "bbb"
  6.             DoCmd.PrintOut acPages, 3, 3, , 1
  7.         Case "ccc"
  8.             DoCmd.PrintOut acPages, 4, 4, , 1
  9.         Case "ddd"
  10.             DoCmd.PrintOut acPages, 5, 5, , 1
  11.         Case Else
  12.     End Select
  13. End Function
Then on the OnClick() event of your button, use this code:
Expand|Select|Wrap|Line Numbers
  1. Call PrintOut(Me.Text28)
  2.  
Aug 13 '19 #4
kledki
20
Thank you so much for your help
Aug 13 '19 #5
Nauticalgent
100 64KB
You're very welcome, happy to help.
Aug 13 '19 #6

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

Similar topics

5
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...
2
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...
4
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...
2
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. ...
7
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...
12
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;...
5
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; ...
1
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...
1
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...
1
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
0
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
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...
0
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...
0
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...
1
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)...
0
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
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.