473,396 Members | 2,016 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,396 software developers and data experts.

updating a field with code

Hi me again, last problem this time thoough! :¬)

One table of my database is called Loans, and the fields in question here are
Return Date and Days Late. Basically, what I want is the days late to be worked
out automatically from return date. The user enters the return date in a form
(Add Loan) when creating a new loan. The code that works out the days late will
have to be called whenever the database opens, which I don't know how to do.
What code would I have to use and where would i put it? Also, if the return
date is greater than todays date, i just want days late to be 0. I know in
pseudo code it would be something like

while there are more records

Dim DateDifference As Integer
If ([Return Date] >= Now()) Then
DateDifference = 0
Else
DateDifference = DateDiff("y", [Return Date], Now())
End If

endwhile

Loans.[Days Late] = DateDifference

something like this, I haven't learnt much coding though and this is just what
I have managed to get together from the help files

Thanx for any help, my teacher told me to ask here because he wasn't sure
either.

Donovan
Nov 12 '05 #1
5 1496
"DangerD321" <da********@aol.com> wrote in message
news:20***************************@mb-m22.aol.com...
Hi me again, last problem this time thoough! :¬)

One table of my database is called Loans, and the fields in question here are Return Date and Days Late. Basically, what I want is the days late to be worked out automatically from return date. The user enters the return date in a form (Add Loan) when creating a new loan. The code that works out the days late will have to be called whenever the database opens, which I don't know how to do. What code would I have to use and where would i put it? Also, if the return date is greater than todays date, i just want days late to be 0. I know in
pseudo code it would be something like

while there are more records

Dim DateDifference As Integer
If ([Return Date] >= Now()) Then
DateDifference = 0
Else
DateDifference = DateDiff("y", [Return Date], Now())
End If

endwhile

Loans.[Days Late] = DateDifference

something like this, I haven't learnt much coding though and this is just what I have managed to get together from the help files

Thanx for any help, my teacher told me to ask here because he wasn't sure
either.

Donovan

Do not use code! Instead, the days overdue should be put into a query
expression so it is always correct, e.g.

SELECT Loans.ID, Loans.DateDue,
IIf((Date()-[DateDue])>0,Date()-[DateDue],0) AS DaysOverdue
FROM tblLoans

This will do what you have asked for, but why not change the query to return
DaysLeft which will could be either a positive or negative number or, if due
today, then zero. More importantly, where is the field to say whether it
has actually been returned or not? The first query will show loans becoming
more and more overdue since there is no field to say they have been
returned.

Fletcher
Nov 12 '05 #2
thanx, itll be much easier now, although i really don't understand that query
:¬S
Nov 12 '05 #3
"DangerD321" <da********@aol.com> wrote in message
news:20***************************@mb-m22.aol.com...
thanx, itll be much easier now, although i really don't understand that query :¬S


It's not that difficult:

SELECT Loans.ID, Loans.DateDue,
IIf((Date()-[DateDue])>0,Date()-[DateDue],0) AS DaysOverdue
FROM tblLoans

It simply takes 2 actual fields from the table: tblLoans.ID and
tblLoans.DateDue and calculates a third. This third column is given an
alias of "DaysOverdue" using the keyword "AS".

You could have used simply Date()-[DateDue] AS DaysOverdue but you said you
needed it to show zero if the loan was not actually overdue. To do this you
use the IIF function which you can look up in the help file.

IIf((Date()-[DateDue])>0,Date()-[DateDue],0) AS DaysOverdue

Which says that if (today's date) - (the due date) > 0 then show this
positive amount, otherwise show zero.

Anyway, a better solution might be:

[DateDue]-Date() AS DaysLeft

which would give the number of days left positive, negative (overdue), or
zero (due today)
Fletcher
Nov 12 '05 #4
i want the actual value to be stored in the Loans table though.

SELECT IIf((Date()-[Return Date])>0,Date()-[Return Date],0) AS DaysOverdue FROM
Loans;

works but where can i put it if i want it to actually store the value in the
table under Days Late?

Thanx
Nov 12 '05 #5
da********@aol.com (DangerD321) wrote in message news:<20***************************@mb-m05.aol.com>...
i want the actual value to be stored in the Loans table though.

SELECT IIf((Date()-[Return Date])>0,Date()-[Return Date],0) AS DaysOverdue FROM
Loans;

works but where can i put it if i want it to actually store the value in the
table under Days Late?

Thanx


Bad idea... you'd have to update your table every day. Okay, now that
I've said it's a bad idea, ...

You CAN do it, although it's not advisable... Create a query, like
Fletcher showed, then turn it into an update query, and stuff the
"days overdue" value back into the table.
Nov 12 '05 #6

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

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
1
by: Srinadh | last post by:
Hi all, We have files with about 20 to 30 fields per row. We are trying to update such files with about 60 rows as contiguous data in a CLOB field. It passes through. But when we try...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
5
by: Ryan Ternier | last post by:
I'm having an issue with an SQL insert statement. It's a very simple statement, and it's causing too much fuss. strSQL = "INSERT INTO tblFieldLayouts(TypeID, FieldID, OrderID, Hidden) VALUES("...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
0
by: teammcs | last post by:
Hey all, I'm new around here but do Admin over @ PHPHelp.com... I've been developing a project for my degree which is basically based around an ATM machine. Basically my problem is related to...
4
by: AlexNunley | last post by:
I've adopted a moderately sized (65k records) active use database (Access 2000, Windows XP). One of the most commonly used forms is whats called the RMA generation field, used to add claim...
2
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
0
by: Mike | last post by:
So here's the situation (.NET 2.0 btw): I have a form, and on this form is a textbox among many other databound controls. The textbox is bound to a field in a data table via the Text property. ...
1
by: cerilocke | last post by:
I have a repeater in which I have a hidden field (input type = hidden), a textbox (asp:TextBox), a checkbox (input type = checkbox) and a label (asp:Label). I have bound all four items to the same...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.