473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

form on open calculation problem

Hi folks.

I have a form, frmHistory, that has the following code for its On Open
event.

=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=
Private Sub Form_Open(Cancel As Integer)

Dim NumDays As Integer

'calculate days overdue, if any
NumDays = DateDiff("d", Me.DateDue, Me.DateReturn)

'reset negatives
If NumDays < 0 Then
NumDays = 0
End If

'calculate & set fine based on member type & number of overdue days
'for staffs, fine = $1.00 / day overdue
If (Me.MemberType = "Staff") And (NumDays > 0) Then
Me.TotalFine = NumDays
End If

'for students, fine = $0.50 / day overdue
If (Me.MemberType = "Student") And (NumDays > 0) Then
Me.TotalFine = NumDays * 0.5
End If

End Sub
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=

What the coding does (or should do) is to calculate the fine a member
has to pay based on the member type and the number of overdue days.
Thus, if frankie is a staff and he is overdue by 3 days, he has to pay
$3.00. But if frankie is a student and he is overdue by 3 days, he has
to pay $1.50.

The problem is that the coding doesn't work. Anyone has any idea why?
Is it because I set the Default View of the form to "Continuous
Forms"? If that is the case then how do I rectify the situation? I'm
using Access 97, if that's important. Thank you.
Nov 13 '05 #1
5 2138
I would put the calculations in a query (or several) and run the query
Form_open and put the answers in a special field.

Your calculation only does it for the current record.

Nicolaas
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004
Nov 13 '05 #2
Put your code n the OnActivate event of the form rather than the OnOpen event.
When the OnOpen event fires, the field values are already set and the form does
not go back and recalculate them.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Aravind" <so**********@hotmail.com> wrote in message
news:61**************************@posting.google.c om...
Hi folks.

I have a form, frmHistory, that has the following code for its On Open
event.

=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=
Private Sub Form_Open(Cancel As Integer)

Dim NumDays As Integer

'calculate days overdue, if any
NumDays = DateDiff("d", Me.DateDue, Me.DateReturn)

'reset negatives
If NumDays < 0 Then
NumDays = 0
End If

'calculate & set fine based on member type & number of overdue days
'for staffs, fine = $1.00 / day overdue
If (Me.MemberType = "Staff") And (NumDays > 0) Then
Me.TotalFine = NumDays
End If

'for students, fine = $0.50 / day overdue
If (Me.MemberType = "Student") And (NumDays > 0) Then
Me.TotalFine = NumDays * 0.5
End If

End Sub
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=

What the coding does (or should do) is to calculate the fine a member
has to pay based on the member type and the number of overdue days.
Thus, if frankie is a staff and he is overdue by 3 days, he has to pay
$3.00. But if frankie is a student and he is overdue by 3 days, he has
to pay $1.50.

The problem is that the coding doesn't work. Anyone has any idea why?
Is it because I set the Default View of the form to "Continuous
Forms"? If that is the case then how do I rectify the situation? I'm
using Access 97, if that's important. Thank you.

Nov 13 '05 #3
"PC Datasheet" <sp**@nospam.spam> wrote in
news:Xc*******************@newsread3.news.atl.eart hlink.net:
Put your code n the OnActivate event of the form rather than
the OnOpen event. When the OnOpen event fires, the field
values are already set and the form does not go back and
recalculate them.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word
Applications
re******@pcdatasheet.com
www.pcdatasheet.com

Even in the OnActivate event you will only get the calculation done
for the first visible record. In hte on current event will show the
current fine in all rows.

Since the OP specified he wanted continuous forms, the only way to
get trustable answers is to put the calculation in a query.

Aravind, you need to move the code to a module, convert it to a
public function, and call it as an expression in the query that
becomes the recordsource for your form.

Bob Quintal


"Aravind" <so**********@hotmail.com> wrote in message
news:61**************************@posting.google.c om...
Hi folks.

I have a form, frmHistory, that has the following code for
its On Open event.

=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=
Private Sub Form_Open(Cancel As Integer)

Dim NumDays As Integer

'calculate days overdue, if any
NumDays = DateDiff("d", Me.DateDue, Me.DateReturn)

'reset negatives
If NumDays < 0 Then
NumDays = 0
End If

'calculate & set fine based on member type & number of
overdue days 'for staffs, fine = $1.00 / day overdue
If (Me.MemberType = "Staff") And (NumDays > 0) Then
Me.TotalFine = NumDays
End If

'for students, fine = $0.50 / day overdue
If (Me.MemberType = "Student") And (NumDays > 0) Then
Me.TotalFine = NumDays * 0.5
End If

End Sub
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=

What the coding does (or should do) is to calculate the fine
a member has to pay based on the member type and the number
of overdue days. Thus, if frankie is a staff and he is
overdue by 3 days, he has to pay $3.00. But if frankie is a
student and he is overdue by 3 days, he has to pay $1.50.

The problem is that the coding doesn't work. Anyone has any
idea why? Is it because I set the Default View of the form to
"Continuous Forms"? If that is the case then how do I rectify
the situation? I'm using Access 97, if that's important.
Thank you.



Nov 13 '05 #4
Rob
I agree with Nicolaas. If you want to display it in continuous form,
then put the code in a query. If not, your code would work fine on a
"single form" view, just put the code in the CURRENT Event. THen as
they move from record to record, it would recalculate fine.
Nov 13 '05 #5
On Mon, 24 May 2004 12:51:03 GMT, "PC Datasheet" <sp**@nospam.spam> wrote:
Put your code n the OnActivate event of the form rather than the OnOpen event.
When the OnOpen event fires, the field values are already set and the form does
not go back and recalculate them.


Actually this is not entirely correct. When OnOpen fires the data has not yet been loaded therefore referencing a bound
control on the form will fail as there is no data present. You are correct in saying that moving the code to a later
event should solve the problem. I would use OnLoad unless the values need to be recalculated when focus returns to the
form from another object. In this case OnActivate would be the choice.
Wayne Gillespie
Gosford NSW Australia
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Newbie | last post by:
OK, this may be impossible since I'm using 3rd party shopping cart ASP software, but I've been able to finagle a lot of other stuff I thought wouldn't work, so here we go: I'm using a form in...
3
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60...
0
by: gavo | last post by:
Hi. using A2K; i have a form containing a continous subform. The question is, how can i call a calculation for one of the fields in the continous subform from the main form. At the moment i...
11
by: ian.davies52 | last post by:
Is there anything I can do about the apparent limit on the number of textboxes that have calculations as their control source on a form or report in ms-access? I have a query that pulls together...
4
by: vg-mail | last post by:
Hello all, I have identical design for form and report but I am getting calculation error on form and everything is OK on report. The form and report are build up on SQL statement. The...
2
by: semutmerah | last post by:
hi.. my english maybe wrong.. but hope somebody can understand me :) I did created 3 forms. "MainForm" , "CalForm" , "WaitForm". On "MainForm", I did put a command button called "Run". ...
4
meLady
by: meLady | last post by:
Hello, I have a form called feedback with a subform called feedback Options. I did some counting calculation in master form "feedback" at the bottom page. the calculation is about count the...
2
by: campos | last post by:
Hi all, I ran into a headache problem. I have a windows form with a progress bar on it. Then I new a thread to do calculation for a long time. I want the progress bar to show the calculation...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.