2 replies
by bob sellman
Here's a simple example that should be a reasonable guide for you:
Assume you have a module that contains a function that looks something like this (to calculate the square root of the number passed to it):
Function ShowMe(lngVal As Long) As Double
ShowMe = sqrt(lngVal)
End Function
Let's assume that on your form you have one control called txtValue which is where the value will be entered and a second control called txtResult which is where you want to result of your function tobe displayed.
If you want txtResult calculated (or recalculated) when a user enters or changes the number in txtValue, then for the OnUpdate property of txtValue you put the following code:
Private Sub txtValue_AfterUpdate()
Me.txtResult = ShowMe(Me.txtValue)
End Sub
You can of course have one or both controls use a column from your table as its control source, if appropriate. This will then update the value in the table. If you don't want the result actually displayed, just set the visible property of txtResult to False.
If you want some functions to run automatically when you go to a different record, (also) place similar code in the OnCurrent property of the form so the code will be run for every record that is current.
by bob sellman
Sorry, I forgot to correct the square root function to the correct syntax before posting the answer. The line in the function should read:
ShowMe = sqr(lngVal)
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending