Attach a subroutine to an unbound Text box?

Hi. What you could try to do is create a function that returns a value. You can then assign the funtion call as a Control Source for your unbound textbox. Hope that helps...
Hi. What you could try to do is create a function that returns a value. You can then assign the funtion call as a Control Source for your unbound textbox. Hope that helps...
Just getting around to trying this. What is the syntax that is needed to call a function from within the control source properties box?
 
Just getting around to trying this. What is the syntax that is needed to call a function from within the control source properties box?
That would be:

=FunctionName()
 
That is exactly what I thought and my function in that form does nothing. Has no syntax error, but has no output in the text box. Must be something wrong with the function as written. Will attempt to rebuild it. Thanks for the quick reply.
 
That is exactly what I thought and my function in that form does nothing. Has no syntax error, but has no output in the text box. Must be something wrong with the function as written. Will attempt to rebuild it. Thanks for the quick reply.
Hi. I did suggest for you to modify your function to return a value. So, if you didn't do that yet, then "nothing" will happen yet.
 
Hi. What you could try to do is create a function that returns a value. You can then assign the funtion call as a Control Source for your unbound textbox. Hope that helps...
Have been trying to get a function to act as the control source as you suggested. The Function is simple and has no syntax or other errors but when I place it in the control source property it does not execute. Instead when I try to do a print preview of the report, the first thing that happens is that I get a msgbox asking for parameters for the Function. Do you have any idea what could be wrong? Thanks.
 
Have been trying to get a function to act as the control source as you suggested. The Function is simple and has no syntax or other errors but when I place it in the control source property it does not execute. Instead when I try to do a print preview of the report, the first thing that happens is that I get a msgbox asking for parameters for the Function. Do you have any idea what could be wrong? Thanks.
Please post said function. Thanks.
 
Wrote this just as a trial function to see if it might work. It is not fully completed as yet.
Option Compare Database
Option Explicit

Public Function SplitTotal(TotalA As Double, TotalB As Double)

If Me.CODE1 = "AS" Or "AL" Then Me.TotalA = Me.SPLIT1 * Me.Fee


Else: Me.TotalA = Me.SPLIT1 * Me.Amount

End If


End Function
 
Wrote this just as a trial function to see if it might work. It is not fully completed as yet.
Option Compare Database
Option Explicit

Public Function SplitTotal(TotalA As Double, TotalB As Double)

If Me.CODE1 = "AS" Or "AL" Then Me.TotalA = Me.SPLIT1 * Me.Fee


Else: Me.TotalA = Me.SPLIT1 * Me.Amount

End If


End Function
And how are you using it on the form? By the way, that function still doesn't return a value. Here's an example:
Code:
Public Function Test() As String
    Test = "It is now " & Now()
End Function
Sent from phone...
 
I have a subreport that has the fields that are in the function code. I created a txtbox called TotalA and hoped to populate it from within the functions output. That is why I thought you said to place the function in the control source box. Thought it would execute from there. Was that wrong?
 
I have a subreport that has the fields that are in the function code. I created a txtbox called TotalA and hoped to populate it from within the functions output. That is why I thought you said to place the function in the control source box. Thought it would execute from there. Was that wrong?
Hi. I updated my post above. Yes, that's the second part of what I said earlier. The first part was to modify the function to return a value.
 
I thought what I was doing was returning a value. What might I do to make this return a value?
 
I thought what I was doing was returning a value. What might I do to make this return a value?
To return a value, you have to assign the value to the function. Take a look at my example earlier.
 
I thought the If Then statement was assigning the value (Split1 * Fee) to TotalA.
 
I thought the If Then statement was assigning the value (Split1 * Fee) to TotalA.
Hi. That was your old way of doing it, which wasn't working. I am recommending to you a new way of doing it.
 
Hi. That was your old way of doing it, which wasn't working. I am recommending to you a new way of doing it.
Okay, sorry, I was on my phone earlier, so I couldn't provide more details. But now, I can.

So, let's say you have a form with three boxes. Let's say you enter a value in box1 and box2, and you want to add them up and show the total in box3. Further, let's say you decide to write a function to do that. It might look something like this:
Code:
Public Function AddThemUp(val1 As Long, val2 As Long) As Long
    AddThemUp = val1 + val2
End Function
So, with that function, all you need to put in box 3 is something like this:
Code:
=AddThemUp([box1],[box2])
Hope that makes sense...
 
I think I understand what you are saying, but I have an additional problem in that most of the time I would just multiply Split1 * Fee based upon what was in the Code1 field. But, at other times, still based upon what was in Code1 it would be necessary to multiply Split1 * Amount (another field). That was why I was using the If Then statement. I am extremely grateful for what you have done to help me. Thank you for all your effort.
 
I think I understand what you are saying, but I have an additional problem in that most of the time I would just multiply Split1 * Fee based upon what was in the Code1 field. But, at other times, still based upon what was in Code1 it would be necessary to multiply Split1 * Amount (another field). That was why I was using the If Then statement. I am extremely grateful for what you have done to help me. Thank you for all your effort.
Hi. Should not be a problem. I wasn't saying you need to throw away your code. You can keep all your if/then statements. All I was saying was modify it to "return a value," and I already told you how to do that - just add a line to assign the result to the name of the function.
 

Users who are viewing this thread

Back
Top Bottom