473,395 Members | 1,815 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,395 software developers and data experts.

Automatically Updating data end of month

Hi all,

I sincerly thank you all in advance for your help to solve this
problem.

I have been trying to find a solution to this problem for sometime now
but have failed.

I am working on a project that requires updating data every month.
A typical examle is an apartment rental software but could be applied
in any other database.

I have a tenant table (tblTenant) with all its relevent fields.
I also have a tenant transaction table (tblTenantTransaction) with all
its relevent fields

tblTenant is one side of the table and tblTenantTransaction is many
side of the table.

tblTenant table and tblTenantTransaction table are linked by TenantID
field

In tblTenant table, among other details I have a field that stores
tenants monthly rent (this stays static). Each Tenant pays different
amount of rent every month.

In tblTenantTransaction table, among other fields I have these fields
as well
I)TransDate field (Transaction date field)
II)Debit field (Hold the amount that tenant has to pay every month)

I am looking for a way (either in SQL or VBA) to automatically enter
the date in TransDate filed (taking in the last day of the month)and
also required amount in the bedit field of tblTenantTransaction table
by looking for its respective rent amount in tblTenant table.

The code should first check to see if transaction for the previous
month has been entered or not, if it has than it should continue with
the above mentioned transacton, otherwise warn me with error msg.

This should also take care of the months that have either 28, 29, 30
or 31 days.

Once again I thank you all in advance for your help
Nov 12 '05 #1
6 2960
DFS
Hasanain,
Try this:
'DAYS IN THE MONTH ARRAY
Dim monthMaxDay(12) As Byte
monthMaxDay(1) = 31 'JAN
monthMaxDay(2) = 28 'FEB
monthMaxDay(3) = 31 'MAR
monthMaxDay(4) = 30 'APR
monthMaxDay(5) = 31 'MAY
monthMaxDay(6) = 30 'JUN
monthMaxDay(7) = 31 'JUL
monthMaxDay(8) = 31 'AUG
monthMaxDay(9) = 30 'SEP
monthMaxDay(10) = 31 'OCT
monthMaxDay(11) = 30 'NOV
monthMaxDay(12) = 31 'DEC

'HANDLE LEAP YEARS - occur in years exactly divisible by four,
' except that years ending in 00 are leap years
' only if they are divisible by 400.
' So, 1700, 1800, 1900, 2100, and 2200 are not leap years.
' But 1600, 2000, and 2400 are leap years.

dim calYear as integer
calYear = datepart("yyyy",date())
If (calYear Mod 4 = 0 And Right(CStr(calYear), 2) <> "00") Or
(Right(CStr(calYear), 2) = "00" And calYear Mod 400 = 0) Then
monthMaxDay(2) = 29
End If
'TODAY IS THE LAST DAY OF THE MONTH
if datePart("d",date()) = monthMaxDay(datePart("m",date())) then

'DETERMINE PRIOR MONTH AND YEAR
Dim priorMonth as byte, transYear as integer
priorMonth = datePart("m",date()) - 1
transYear = datePart("yyyy",date())
if priorMonth = 0 then 'IF CURRENT MONTH = JANUARY
priorMonth = 12
transYear = transYear - 1
endif

'PROCESS FOR ALL TENANTS
set rs = db.openRecordset("SELECT TenantID, TenantName, TenantRent FROM
tblTenant ORDER BY TenantID;")
do until rs.eof

'LOOK FOR PRIOR MONTH PAYMENT
set rs1 = db.openRecordset("SELECT DISTINCT * FROM tblTenantTransaction
WHERE TenantID = " & rs("TenantID") & " AND (datePart("m",[TransDate]) = " &
priorMonth & " and datePart("yyyy",[TransDate] = " & transYear & ");")

'NO PRIOR MONTH PAYMENT
if rs1.recordCount = 0 then
msgbox "Prior month rent for Tenant " & tenantID & " not entered"
'note - you might want to write these exceptions out to a log table
endif

'PRIOR MONTH PAYMENT FOUND, WRITE CURRENT MONTH TO TABLE
if rs1.recordCount > 0 then
db.execute("INSERT INTO tblTenantTransaction (TenantID, TransDate,
DebitAmt) VALUES (" & tenantID & ", #" & date() & "#, " & rs("TenantRent") &
");")
endif

'NEXT TENANT
rs.movenext
Loop

rs.close

endif

*** That should do it for you, or come close.

"Hasanain F. Esmail" <ha*******@yahoo.com> wrote in message
news:27**************************@posting.google.c om...
Hi all,

I sincerly thank you all in advance for your help to solve this
problem.

I have been trying to find a solution to this problem for sometime now
but have failed.

I am working on a project that requires updating data every month.
A typical examle is an apartment rental software but could be applied
in any other database.

I have a tenant table (tblTenant) with all its relevent fields.
I also have a tenant transaction table (tblTenantTransaction) with all
its relevent fields

tblTenant is one side of the table and tblTenantTransaction is many
side of the table.

tblTenant table and tblTenantTransaction table are linked by TenantID
field

In tblTenant table, among other details I have a field that stores
tenants monthly rent (this stays static). Each Tenant pays different
amount of rent every month.

In tblTenantTransaction table, among other fields I have these fields
as well
I)TransDate field (Transaction date field)
II)Debit field (Hold the amount that tenant has to pay every month)

I am looking for a way (either in SQL or VBA) to automatically enter
the date in TransDate filed (taking in the last day of the month)and
also required amount in the bedit field of tblTenantTransaction table
by looking for its respective rent amount in tblTenant table.

The code should first check to see if transaction for the previous
month has been entered or not, if it has than it should continue with
the above mentioned transacton, otherwise warn me with error msg.

This should also take care of the months that have either 28, 29, 30
or 31 days.

Once again I thank you all in advance for your help

Nov 12 '05 #2
Another way to get the last date in a month for any given date:

Private Function LastDateInMonth(TargetDate As Date)
Dim DD As Date
DD = DateAdd("m", 1, TargetDate)
DD = DatePart("m", DD) & "/1/" & DatePart("yyyy", DD)
LastDateInMonth = DateAdd("d", -1, DD)
End Function

"DFS" <no******@nospam.com> wrote in message
news:vt************@corp.supernews.com...
Hasanain,
Try this:
'DAYS IN THE MONTH ARRAY
Dim monthMaxDay(12) As Byte
monthMaxDay(1) = 31 'JAN
monthMaxDay(2) = 28 'FEB
monthMaxDay(3) = 31 'MAR
monthMaxDay(4) = 30 'APR
monthMaxDay(5) = 31 'MAY
monthMaxDay(6) = 30 'JUN
monthMaxDay(7) = 31 'JUL
monthMaxDay(8) = 31 'AUG
monthMaxDay(9) = 30 'SEP
monthMaxDay(10) = 31 'OCT
monthMaxDay(11) = 30 'NOV
monthMaxDay(12) = 31 'DEC

'HANDLE LEAP YEARS - occur in years exactly divisible by four,
' except that years ending in 00 are leap years
' only if they are divisible by 400.
' So, 1700, 1800, 1900, 2100, and 2200 are not leap years.
' But 1600, 2000, and 2400 are leap years.

dim calYear as integer
calYear = datepart("yyyy",date())
If (calYear Mod 4 = 0 And Right(CStr(calYear), 2) <> "00") Or
(Right(CStr(calYear), 2) = "00" And calYear Mod 400 = 0) Then
monthMaxDay(2) = 29
End If
'TODAY IS THE LAST DAY OF THE MONTH
if datePart("d",date()) = monthMaxDay(datePart("m",date())) then

'DETERMINE PRIOR MONTH AND YEAR
Dim priorMonth as byte, transYear as integer
priorMonth = datePart("m",date()) - 1
transYear = datePart("yyyy",date())
if priorMonth = 0 then 'IF CURRENT MONTH = JANUARY
priorMonth = 12
transYear = transYear - 1
endif

'PROCESS FOR ALL TENANTS
set rs = db.openRecordset("SELECT TenantID, TenantName, TenantRent FROM
tblTenant ORDER BY TenantID;")
do until rs.eof

'LOOK FOR PRIOR MONTH PAYMENT
set rs1 = db.openRecordset("SELECT DISTINCT * FROM tblTenantTransaction
WHERE TenantID = " & rs("TenantID") & " AND (datePart("m",[TransDate]) = " & priorMonth & " and datePart("yyyy",[TransDate] = " & transYear & ");")

'NO PRIOR MONTH PAYMENT
if rs1.recordCount = 0 then
msgbox "Prior month rent for Tenant " & tenantID & " not entered"
'note - you might want to write these exceptions out to a log table
endif

'PRIOR MONTH PAYMENT FOUND, WRITE CURRENT MONTH TO TABLE
if rs1.recordCount > 0 then
db.execute("INSERT INTO tblTenantTransaction (TenantID, TransDate,
DebitAmt) VALUES (" & tenantID & ", #" & date() & "#, " & rs("TenantRent") & ");")
endif

'NEXT TENANT
rs.movenext
Loop

rs.close

endif

*** That should do it for you, or come close.

"Hasanain F. Esmail" <ha*******@yahoo.com> wrote in message
news:27**************************@posting.google.c om...
Hi all,

I sincerly thank you all in advance for your help to solve this
problem.

I have been trying to find a solution to this problem for sometime now
but have failed.

I am working on a project that requires updating data every month.
A typical examle is an apartment rental software but could be applied
in any other database.

I have a tenant table (tblTenant) with all its relevent fields.
I also have a tenant transaction table (tblTenantTransaction) with all
its relevent fields

tblTenant is one side of the table and tblTenantTransaction is many
side of the table.

tblTenant table and tblTenantTransaction table are linked by TenantID
field

In tblTenant table, among other details I have a field that stores
tenants monthly rent (this stays static). Each Tenant pays different
amount of rent every month.

In tblTenantTransaction table, among other fields I have these fields
as well
I)TransDate field (Transaction date field)
II)Debit field (Hold the amount that tenant has to pay every month)

I am looking for a way (either in SQL or VBA) to automatically enter
the date in TransDate filed (taking in the last day of the month)and
also required amount in the bedit field of tblTenantTransaction table
by looking for its respective rent amount in tblTenant table.

The code should first check to see if transaction for the previous
month has been entered or not, if it has than it should continue with
the above mentioned transacton, otherwise warn me with error msg.

This should also take care of the months that have either 28, 29, 30
or 31 days.

Once again I thank you all in advance for your help


Nov 12 '05 #3
You can get the last date in the month for any given date using:

DateSerial(Year(InputDate), Month(InputDate) + 1, 0)

For example:
?DateSerial(Year(Date()), Month(Date()) + 1, 0)
31/12/2003

--
HTH
Van T. Dinh


"Randy Harris" <ra***@SpamFree.com> wrote in message
news:Mp**********************@newssvr28.news.prodi gy.com...
Another way to get the last date in a month for any given date:

Private Function LastDateInMonth(TargetDate As Date)
Dim DD As Date
DD = DateAdd("m", 1, TargetDate)
DD = DatePart("m", DD) & "/1/" & DatePart("yyyy", DD)
LastDateInMonth = DateAdd("d", -1, DD)
End Function


Nov 12 '05 #4
"Van T. Dinh" <Va***********@PlseUseNewsGroup.bigpond.com> wrote in message
news:fN******************@news-server.bigpond.net.au...
You can get the last date in the month for any given date using:

DateSerial(Year(InputDate), Month(InputDate) + 1, 0)

For example:
?DateSerial(Year(Date()), Month(Date()) + 1, 0)
31/12/2003

--
HTH
Van T. Dinh
Oooh. Even better. Thanks!

"Randy Harris" <ra***@SpamFree.com> wrote in message
news:Mp**********************@newssvr28.news.prodi gy.com...
Another way to get the last date in a month for any given date:

Private Function LastDateInMonth(TargetDate As Date)
Dim DD As Date
DD = DateAdd("m", 1, TargetDate)
DD = DatePart("m", DD) & "/1/" & DatePart("yyyy", DD)
LastDateInMonth = DateAdd("d", -1, DD)
End Function


Nov 12 '05 #5
DFS
Doesn't the FAQ state

"Don't show up another poster by providing a one-line fix that replaces 20
lines of the original poster's spaghetti code."?
"Van T. Dinh" <Va***********@PlseUseNewsGroup.bigpond.com> wrote in message
news:fN******************@news-server.bigpond.net.au...
You can get the last date in the month for any given date using:

DateSerial(Year(InputDate), Month(InputDate) + 1, 0)

For example:
?DateSerial(Year(Date()), Month(Date()) + 1, 0)
31/12/2003

--
HTH
Van T. Dinh


"Randy Harris" <ra***@SpamFree.com> wrote in message
news:Mp**********************@newssvr28.news.prodi gy.com...
Another way to get the last date in a month for any given date:

Private Function LastDateInMonth(TargetDate As Date)
Dim DD As Date
DD = DateAdd("m", 1, TargetDate)
DD = DatePart("m", DD) & "/1/" & DatePart("yyyy", DD)
LastDateInMonth = DateAdd("d", -1, DD)
End Function


Nov 12 '05 #6

"DFS" <no******@nospam.com> wrote in message
news:vt************@corp.supernews.com...
Doesn't the FAQ state

"Don't show up another poster by providing a one-line fix that replaces 20
lines of the original poster's spaghetti code."?
"Van T. Dinh" <Va***********@PlseUseNewsGroup.bigpond.com> wrote in message news:fN******************@news-server.bigpond.net.au...
You can get the last date in the month for any given date using:

DateSerial(Year(InputDate), Month(InputDate) + 1, 0)

For example:
?DateSerial(Year(Date()), Month(Date()) + 1, 0)
31/12/2003

--
HTH
Van T. Dinh


"Randy Harris" <ra***@SpamFree.com> wrote in message
news:Mp**********************@newssvr28.news.prodi gy.com...
Another way to get the last date in a month for any given date:

Private Function LastDateInMonth(TargetDate As Date)
Dim DD As Date
DD = DateAdd("m", 1, TargetDate)
DD = DatePart("m", DD) & "/1/" & DatePart("yyyy", DD)
LastDateInMonth = DateAdd("d", -1, DD)
End Function




It may do - but I find it useful to see ALL the ways that people use to
code. I can then extend my own knowledge of code this way - I can often
understand the verboser code and link it to the terse code. I would not
necessarily be able to code tersely by myself and am grateful for the
'learning curve' shortener!! :>]}

Nick
Nov 12 '05 #7

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

Similar topics

6
by: Simon | last post by:
Hello, I am trying to update some varchar2 fields, which are storing dates. I am trying to set a 'to date' with the next minumum from date i.e from date | to date 01/01/1901 ...
13
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
4
by: rdemyan via AccessMonster.com | last post by:
My application is calculation intensive and the servers are agonizingly slow. Administrators of my application only update the backends once a month (twice a month max). So, my launching program...
11
by: kavithadevan | last post by:
Hi I am trying to create some websites in that website i have images field in that image field(totally i have 12 images) in my website i want to update my images according to month.If the...
0
by: preeti13 | last post by:
i have a two tables employeenominations and reason if someone storing a data first time it will store into the employeenominations table if name is already exist it will store into the reason table...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
11
by: xelA | last post by:
Thanks, it worked. Another problem: Hey folks, where is the bug in this code? When updating the date field, it is updating all the records in the table with the same value (e.g. 2008-01-07) instead...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.