Calulations

NewfieSarah

Registered User.
Local time
Today, 09:09
Joined
Feb 11, 2005
Messages
193
I have a new table called CONRESVALCALC with contain lots of fields. I need to use a command buttons so when the buttons is clicked then a calculation is performed for that specific button. The field Mainarea and unitval have to be multiplyed to have portionval appear. This button can be pressed anytime when adding a new record. or editing. suggestions?? Thanks

sarah
 
I'm a little concerned that Mainarea and Unitval might be null. I'm using the Nz function as a safeguard.

I'd put the following code on the OnClick event for the command button.

Code:
With Me
    .portionval = Nz(.Mainarea,0) * Nz(.Unitval,0)
End With
 
So what is that code doing exactally??It is doing the calcculation? So can you explaing the NZ function a bit more? I would like to know a bit more about it before just adding the code. Thanks
 
The Nz (NullZero) function takes two arguments., a control name and a value if the control is null.

The code examines the two controls that you initially mention Mainarea and Unitval. The values of the two controls are multiplied and the result is passed to portionval. If either of the two controls are null a zero is passed to portionval.
 
Thank a lot FlyerMike, I hope it works. I will get back to you about, it. one more question is that "." suppose to be in frount of "." portionval??Thanks
 
I just tryed it and I got an over flow error? as well I had to remover the "." infront of all the variables. So what is an over flow error mean??
 
NewfieSarah said:
...field Mainarea and unitval have to be multiplyed to have portionval appear.

The code that FlyerMike gave was assuming that Mainarea, unitval and portionval are controls, not fields in your table.

Try replacing those with your controls, the ones that are bound to the above fields.
 
An overflow error occurs when a passed value exceeds the capability of the receiving variable or field.

Q1)
You included the "With Me" and "End With" lines, correct?

Q2)
What are the control names on your form? I assumed the control names were from your original message.

Q3)
What type of field definitions do you have for the three fields?
 
yes those are the control names, I did add the "with me" and "end with" code. They types are integer. but I changed the portionval to currency. Now I have a error cannot perform with out seting focus, and i set focus to the text field and then it said cannot set focus to that field? have a good weekend all. Off for the day. I'll get back to you soon. Thanks for the messages.
 
This doesn't sound right....

Is it possible to post a copy of the DB with all confidential data removed?
 
Nope I am sorry i cannot post my DB. And I still cant get this code to work. Any more ideas and help would be great!
 
NewfieSarah said:
I have a new table called CONRESVALCALC with contain lots of fields. I need to use a command buttons so when the buttons is clicked then a calculation is performed for that specific button. The field Mainarea and unitval have to be multiplyed to have portionval appear. This button can be pressed anytime when adding a new record. or editing. suggestions?? Thanks

sarah


Why don't you simply use a query , e.g. :
Select query > portionval : [Mainarea]*[unitval]. Just ensure that the
field properties of both fields are the same in the table ( i.e. number).
 
Thanks everyone I resolved the issue, Thanks for all the help. I uesd. It works just fine, unless you delete a record, it uses the same number again. So i think I might have to validate it, I am not sure how and what the code is for that, but I think it should work. If anyone has any ideas that would be great. Thanks
Dim myCount As Long
PERMIT_NO.SetFocus
myCount = 1 + Nz(DCount("*", "Development Permits"), 0)
PERMIT_NO.Text = Format(STRDATE, "yy") & " - " & myCount
 

Users who are viewing this thread

Back
Top Bottom