foxxrunning
Member
- Local time
- Yesterday, 23:32
- Joined
- Oct 6, 2019
- Messages
- 109
Will do that. Thanks again. I think I understand now.
Okay. Good luck. Let us know if it still doesn't work.Will do that. Thanks again. I think I understand now.
Hi. You'll have to show us exactly what you did for us to tell you why it didn't work. For example, rather than using =test(), try using =Date(). Do you still get an error?So I erased my function and just placed your Test() function into the control source. The same thing happened. When I tried to print preview the form the first thing that happens (as was happening in my function) is the a msgbox pops up and asks for the parameters of Test(). Do you have any idea why this is happening?
No, it doesn't mean that. There are two factors, why it might not work. How the function was written, and how it was called. The Date() function does not need an argument, so you can just use =Date(), and you will get the current date back. If you wrote the function to accept arguments, then you'll have to pass it to the function call. For example, in the code I showed you earlier, I used it this way: =AddThemUp([box1],[box2]). That's because the function AddThemup() accepts/expects two arguments. That's why we need to "see" exactly how you called the function (what exactly did you put in the textbox) to tell you why it didn't work.Wow, that is the first time it actually worked. Put Date() into the control source and it placed the date in the field as it is supposed to do. Does that suggest that the function as written was incorrect?
That's correct, assuming you wrote the function to accept two arguments.I wrote this in the control source box =SplitTotal() But I think I see that in the control source box I have to pass both arguments also in the parenthesis of the function, is that correct?
You're welcome. Good luck!I see. Sorry I am so thick. I will rewrite the function with that in mind. Thanks again for your help.
Hi. Please review my sample function again. I used box1 and box2 to call the function but defined the arguments as val1 and val2. So, depending on whether Code1 and Code2 are the fields in your table or not, you will have to apply what I showed you earlier. Also, your function is still not returning a value, because you haven't assigned the return value to the function. If you need help creating and using the function, consider posting a demo version of your db, so we can show you how to do it using your own field names.So I rewrote the Function today and changed the arguments to Code1 and Code2. Here is the code I wrote
Option Compare Database
Option Explicit
Function SplitTotal(Code1 As String, Code2 As String)
If Code1 = "AL" Or "AS" Then
TotalA = [SPLIT1] * [Fee]
If Code1 <> "AL" Or "AS" Then
TotalA = [Amount]
If Code2 = "AF" Then
TotalB = [Split2] * [Fee]
If Code2 <> "AF" Then
TotalB = Null
End If
End Function
Then I placed this into the control source for the TotalA text box on the report. =SplitTotal([CODE1],[CODE2])
When I ran the print preview I again got the msgbox asking for the parameter Code1 and Code2.
Not there yet. Any ideas.?
Hi. It would be nice to see an actual copy of your db. However, did you modify your function to return a value yet? I mentioned it in my last post (now bolded for emphasis).View attachment 80521 View attachment 80521
This is a screen shot of the subreport section of the report. The only fields on it are the Service date, code1 and code 2, description1 and 2, and the two unbound textboxes on the right. In your addThemUp function the Val1 and val 2 are I think my two text boxes. Is that correct? Then in the control source your box1 and box2 refers to the two arguments in the function? Is this enough to see what I am trying to do, or do you need more?
I thought that as well when I wrote it. Will change it.PMFJI, but I think you would also need
instead ofCode:If Code1 = "AL" Or Code1 = "AS" Then
Code:If Code1 = "AL" Or "AS" Then
Same with the other if statements.?