Discussion Locked

Access Database design and code writing

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I'm currently doing a project on developing a computer program that can be used for inventory control. I have designed all the forms i need to send data to the respective tables. I however have failed to write and link certain codes to the forms i have designed especially function codes. Can u please demonstrate for me how i can link function codes in modules that perfrom and return calculations for data entered in the forms?

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.