|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
VBScript - Trying to pull records for the current month
I have a database that tracks the number of certian charges customers call in and make. I've been asked to find a way to send regular emails each day that include the totals for a given day.
I was originally wirting something in ASP, but in my research, I discovered that VBscript is basically the same thing. That, and I can use "AT" to schedule the script to run. Is there any resource I can look at to find what I need to do? The MDB file I'm using has the date field set to 'date' (mm/dd/yyyy) and I need something that can look at what today is, start at the first of the month and count to the current date. I've written a script that lets me pull just the current day's figures, but I don't know how enough to work with dates in vbs. This is the code I have now and it works great for just pulling today's figures. Code:
'-----------------------------------------
' declare variables
'-----------------------------------------
Dim Conn
Dim rs
Dim datetoday
Dim rmrtotal
Dim equipmenttotal
Dim servicetotal
Dim checktotal
Dim cctotal
Dim dailytotal
Dim body
Dim objCDO
'---------------------------------
'Pull today's date into variable and reset other values to zero
'---------------------------------
datetoday = date()
rmrtotal = 0
equipmenttotal = 0
servicetotal = 0
cctotal = 0
checktotal = 0
dailytotal = 0
'---------------------------------
'Create connection to database
'---------------------------------
Set Conn = CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\Inetpub\wwwroot\_private\master.mdb"
set rs = conn.Execute("SELECT * FROM payments WHERE paydate=#" & datetoday & "#")
'-----------------------------------------
'Do the math!
'-----------------------------------------
do until rs.EOF
select case rs("reason")
case "RMR"
rmrtotal = rmrtotal + rs("amount")
case "Add Equipment"
equipmenttotal = equipmenttotal + rs("amount")
case "Service"
servicetotal = servicetotal + rs("amount")
end select
select case rs("paymenttype")
case "Credit Card"
cctotal = cctotal + rs("amount")
case "Check"
checktotal = checktotal + rs("amount")
end select
dailytotal = cctotal + checktotal
rs.movenext
loop
'-----------------------------------------
' prepare email body text
'-----------------------------------------
body = body & "<html><body><table border='1' cellspacing='0' width='*'><tbody>"
body = body & "<tr><td align='center'>Date</td><td align='center'>CC</td><td align='center'>Check</td><td align='center'>RMR</td><td align='center'>Equipment</td><td align='center'>Service</td><td align='center'>Total</td></tr>"
body = body & "<tr><td align='center'>" & datetoday & "</td><td align='center'>" & cctotal & "</td><td align='center'>" & checktotal & "</td><td align='center'>" & rmrtotal & "</td><td align='center'>" & equipmenttotal & "</td><td align='center'>" & servicetotal & "</td><td align='center'>" & dailytotal &"</td></tr>"
body = body & "</tbody></table></body></html>"
'-----------------------------------------
' compile and send email
'-----------------------------------------
Set objCDO = CreateObject("CDO.Message")
objCDO.To = "xxx@xxx.com"
objCDO.From = "xxx@xxx.com"
objCDO.Subject = "Total payments for " & datetoday
objCDO.HTMLBody = Body
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'-----------------------------------------
'Name or IP of Remote SMTP Server
'-----------------------------------------
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.1.9"
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDO.Configuration.Fields.Update
objCDO.Send
'---------------------------------
'Cleanup
'---------------------------------
rs.Close
Set rs = Nothing
Set Conn = Nothing
Set objCDO = Nothing
Can anyone offer me an idea? |
|
#2
|
||||
|
||||
|
Have a look at DateDiff():
http://www.techonthenet.com/access/functions/date/datediff.php
__________________
selwonk |
|
#3
|
|||
|
|||
|
I actually thought I was onto something with dateadd. Here's what I've added, but it doesn't work because dateadd evidently doesn't like variables:
Code:
datetoday = month(date) & "/" & 1 & "/" & year(date)
do until datetoday = date()
...
recordpulling, etc...
...
dateadd("d",1,datetoday)
loop
It keeps giving me "cannot use parentheses when calling a Sub" for the 'dateadd' line. EDIT: Nevermind. Duh... Forgot to make datetoday EQUAL the dateadd line... datetoday = dateadd("d",1,datetoday) Last edited by bryceowen : May 2nd, 2008 at 11:03 AM. |
|
#4
|
||||
|
||||
|
You're looking for records in the current month, yes? If so, try this query
Code:
SELECT * FROM payments
WHERE MONTH(paydate) = MONTH(DATE())
AND YEAR(paydate) = YEAR(DATE())
__________________
Wolffy ------------------------ Teaching people to fish. |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > VBScript - Trying to pull records for the current month |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
![]() |
|