UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Save calculation control to a field    
 
   
klo
post Jun 18 2005, 09:41 AM
Post #1

New Member
Posts: 4



This is clearly a newbie question, right? I just haven't been able to work this out:

In setting up a form, I have created some calculation controls and concatonation controls, such as total, and a custom date code. And I want to write the calculated values into fields in the record. I'll use "Total" as an example:

I've got a control in a form called "Total" that uses a formula in its "Control Source" property to calculate a total. The form beautifully calculates the total after every change. Now I want to save that value into the record, in a field called "Total".

What's the easiest way to save the value of a calculation control to a field in the current record?

Thanks, I've been on this for hours.
Go to the top of the page
 
+
truittb
post Jun 18 2005, 09:48 AM
Post #2

Retired Moderator
Posts: 13,544
From: Texas (Is there anywhere else?)



Welcome to Utter Access.
Do not save a calculated value to a table. You should calculate the value on the fly as needed.
Go to the top of the page
 
+
strive4peace
post Jun 18 2005, 09:49 AM
Post #3

UtterAccess VIP
Posts: 20,210
From: Colorado



Welcome to Utter Access

just as Truitt said... Do not store calculated values -- that is the beauty of them -- they can be calculated anytime. Storing them risks the integrity of your data.

Just as you can make the total show up beautifully on a form, you can do the same on reports.
Go to the top of the page
 
+
klo
post Jun 18 2005, 10:11 AM
Post #4

New Member
Posts: 4



OK, so saving "totals" may not be a good idea.

But I do want to save a concantonated custom code from the date something like this: = UserID & yymmdd & SubNumber. As before, the control is working great.

This one I'd really like to store in the record. Is there a "preferred method" for storing calculations in a record?

Thanks,

Kevin
Go to the top of the page
 
+
strive4peace
post Jun 18 2005, 10:23 AM
Post #5

UtterAccess VIP
Posts: 20,210
From: Colorado



instead of making the equation the ControlSource, the ControlSource of the custom code should be your fieldname. To calculate it, create a function behind the form

CODE
Private Function MakeCode()
   me.CustomCode_controlname = null
   if isnull(me.UserID ) then exit sub
   if isnull(me.SubNumber) then exit sub
   me.CustomCode_controlname = me.UserID & format(date(), "yymmdd") & me.SubNumber
End Function


on the AfterUpdate Event of UserID and SubNumber

=MakeCode()
Go to the top of the page
 
+
klo
post Jun 18 2005, 10:48 AM
Post #6

New Member
Posts: 4



Thanks. This looks great.
Go to the top of the page
 
+
strive4peace
post Jun 18 2005, 10:53 AM
Post #7

UtterAccess VIP
Posts: 20,210
From: Colorado



you're welcome (IMG:http://www.utteraccess.com/forum/style_emoticons/default/wink.gif)

just out of curiosity ... what is the purpose of this custom code?
Go to the top of the page
 
+
klo
post Jun 22 2005, 08:18 AM
Post #8

New Member
Posts: 4



Thanks again.
The below code worked, after tweaking and customizing. The purpose of this is to generate a PO number, made up of user ititials, date, and a sub-number. Looks like this:

KL-050622-1

<<

Private Function MakeCode()
Me!PurchaseOrderNumber = Null
If IsNull(Me.EmployeeID) Then
strMsg = "You must pick a value from the Employee ID list."
strTitle = "Employee ID Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Cancel = True
End
End If
If IsNull(Me.ordersubnumber) Then End
Me!PurchaseOrderNumber = Me.EmployeeID & "-" & Format(OrderDate, "yymmdd") & "-" & Me.ordersubnumber
End Function

>>
Go to the top of the page
 
+
ScottGem
post Jun 22 2005, 08:40 AM
Post #9

UtterAccess VIP / UA Clown
Posts: 25,090
From: LI, NY



As previously advised you should NOT be storing calculated values. There is no need for it since you can use the same expression to display the value whenever needed. You are storing the EmployeeID, the order date and the subnumber. Why waste an extra field on the PO Number? Whereever you need to display the PO Number, be it on forms, reports or in queries just use the expression:

= EmployeeID & "-" & Format(OrderDate, "yymmdd") & "-" & ordersubnumber
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 23rd May 2013 - 09:20 PM