Avatar billede debugger Nybegynder
06. juli 2001 - 12:03 Der er 13 kommentarer og
1 løsning

Afledet værdi

Når jeg har 3 kolonner i en tabel: \"antal\" \"stk_pris\" og \"pris_ialt\"

.. kan jeg så ikke få \"pris_ialt\" til at regne sig selv ud? (den er jo afledt af de to andre... antal * stk_pris)

hvorddan gør jeg det? (det er vel standardværdien, der skal defineres, men hvorddan får jeg \"adgang\" til de andre kolonner?)
Avatar billede terry Ekspert
06. juli 2001 - 12:06 #1
In the before update event on your form you can write

Me.Pris_ialt = Me.antal*me.stk_pris


Avatar billede netsrac Praktikant
06. juli 2001 - 12:07 #2
Vil tro at man i standart værdien kan skrive stk_pris * antal
Avatar billede terry Ekspert
06. juli 2001 - 12:11 #3
But whats that when record isnt yet created?
Avatar billede debugger Nybegynder
06. juli 2001 - 12:21 #4
Nej netsrac det kan man åbenbart ikke :o(

Terry: where du I set the \"Befor Update\" event?
Avatar billede terry Ekspert
06. juli 2001 - 12:26 #5
I am assuming that you enter your data on a form. So in the forms properties (desgign view) you can choose the BeforeUdate event and then just add the code I mentioned. What happens here is that just before the record gets written it takes the values of the other two forms and calculates the third field.
Avatar billede debugger Nybegynder
06. juli 2001 - 12:38 #6
Actually im updating the database via ODBC/ASP, but maybe that will not make any difference...
Avatar billede terry Ekspert
06. juli 2001 - 12:43 #7
So you have the values in your hands before you write to the dB via ASP. Just calculate it yourself, whats hard about that?
Avatar billede debugger Nybegynder
06. juli 2001 - 12:57 #8
Absolutley nothing... i just think it would make the code perform better if access could handle the calculations internaly
Avatar billede terry Ekspert
06. juli 2001 - 13:00 #9
I doubt it would help at all.
Avatar billede debugger Nybegynder
06. juli 2001 - 13:07 #10
Well.. I vill not have to worry about formatting the data for input in a currency-field for one thing.. it seems to me that ther\'s a lot less things that coud go wrong this way.... But i guess it\'s a long discussion.. Your remark that it will not help is now noted :o)
Avatar billede terry Ekspert
06. juli 2001 - 13:17 #11
You dont have to format the data as a currency field if you already have two valid fields (antal + stk_pris). If your using an SQL INSERT statemnet then you could have variable which gets the value from the other two fields.

Dim myVar
myVar = Request.Form(\"Antal\") * Request.form(\"stk_pris\")


Then include myVar in your INSERT statement
No nothing about ASP but I assume it ssomething like that
Avatar billede debugger Nybegynder
06. juli 2001 - 13:24 #12
Yes you\'r right, but what I want is letting the Database \"do the work\".... It\'s not tha i cant accomplish the calculation/insertion ;o)
Avatar billede terry Ekspert
06. juli 2001 - 13:57 #13
I can see the logic in what you are attempting to do but I must admit, I dont think it is possible. I dont think the values of these fields are available when the default value is set into the pris_ialt field. Another thing, why have a pris_ialt field, it can always be calculated?
Avatar billede debugger Nybegynder
06. juli 2001 - 14:25 #14
Your right... im sacreficeing data space in order to eleminate the need for calculations.. wich is not as great an idea as i thougt to begin with.

Im going to drop the pris_ialt field...

Tanks for helping me out :o)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester