WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ   SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log in/Register/PasswordLog in/Register/Password

SQL Statement help

 
   Home -> Office other -> Getting Started RSS
Next:  Getting Started: help on primary keys  
Author Message
Chad

External


Since: Jul 23, 2008
Posts: 1



(Msg. 1) Posted: Wed Jul 23, 2008 4:56 pm
Post subject: SQL Statement help Add to elertz
Archived from groups: microsoft>public>access>gettingstarted (more info?)

Hello, I have a sample database I had found and wanted to change one thing.
It keeps track of how many days a person had taken a "Vacation" in the
current year. I would like to do a similar thing is to keep track of how many
times an employee had an excused tardy within the past 6 months from the
current day. The statement used to get the vacation totals is:

Public Function GetVacationAndHolidays()
Dim strSql
Dim frm As Form
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set frm = Forms!frmCalender
Set db = CurrentDb

' Vacation YTD
strSql = "SELECT Count(InputID) AS TotDays FROM tblInput "
strSql = strSql & "WHERE ((Year([InputDate])=" & CInt(gstrYear) & ") AND
((tblInput.UserID)=" & glngUserID & ") AND
((tblInput.InputText)='Vacation'));"
Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
frm!txtVacYTD = rs!TotDays
rs.Close
strSql = "'"

Set rs = Nothing
db.Close
Set db = Nothing
End Function


How would I count how many times the excused tardy was used for the past 6
months starting on the current day? Thanks!
Back to top
Login to vote
John Spencer

External


Since: Jan 21, 2007
Posts: 285



(Msg. 2) Posted: Thu Jul 24, 2008 8:15 am
Post subject: Re: SQL Statement help Add to elertz [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

StrSQL="SELECT Count(InputID) as TotDay" & _
" FROM TblInput" & _
" WHERE InputDate Between DateAdd(""m"",-6,Date())" & _
" and Date() " & _
" and InputText =""Excused Tardy"" "

Of course, you could simplify the whole thing by using DCount and
skipping the entire function

DCOUNT("*","TblInput","InputDate Between DateAdd(""m"",-6,Date()) and
Date() and InputText =""Excused Tardy"" ")

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


Chad wrote:
> Hello, I have a sample database I had found and wanted to change one thing.
> It keeps track of how many days a person had taken a "Vacation" in the
> current year. I would like to do a similar thing is to keep track of how many
> times an employee had an excused tardy within the past 6 months from the
> current day. The statement used to get the vacation totals is:
>
> Public Function GetVacationAndHolidays()
> Dim strSql
> Dim frm As Form
> Dim db As DAO.Database
> Dim rs As DAO.Recordset
>
> Set frm = Forms!frmCalender
> Set db = CurrentDb
>
> ' Vacation YTD
> strSql = "SELECT Count(InputID) AS TotDays FROM tblInput "
> strSql = strSql & "WHERE ((Year([InputDate])=" & CInt(gstrYear) & ") AND
> ((tblInput.UserID)=" & glngUserID & ") AND
> ((tblInput.InputText)='Vacation'));"
> Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
> frm!txtVacYTD = rs!TotDays
> rs.Close
> strSql = "'"
>
> Set rs = Nothing
> db.Close
> Set db = Nothing
> End Function
>
>
> How would I count how many times the excused tardy was used for the past 6
> months starting on the current day? Thanks!
Back to top
Login to vote
Thanks, Chad

External


Since: Jul 24, 2008
Posts: 15



(Msg. 3) Posted: Thu Jul 24, 2008 10:04 am
Post subject: Re: SQL Statement help Add to elertz [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

John where would I use the DCount at?

"John Spencer" wrote:

>
> StrSQL="SELECT Count(InputID) as TotDay" & _
> " FROM TblInput" & _
> " WHERE InputDate Between DateAdd(""m"",-6,Date())" & _
> " and Date() " & _
> " and InputText =""Excused Tardy"" "
>
> Of course, you could simplify the whole thing by using DCount and
> skipping the entire function
>
> DCOUNT("*","TblInput","InputDate Between DateAdd(""m"",-6,Date()) and
> Date() and InputText =""Excused Tardy"" ")
>
> '====================================================
> John Spencer
> Access MVP 2002-2005, 2007-2008
> The Hilltop Institute
> University of Maryland Baltimore County
> '====================================================
>
>
> Chad wrote:
> > Hello, I have a sample database I had found and wanted to change one thing.
> > It keeps track of how many days a person had taken a "Vacation" in the
> > current year. I would like to do a similar thing is to keep track of how many
> > times an employee had an excused tardy within the past 6 months from the
> > current day. The statement used to get the vacation totals is:
> >
> > Public Function GetVacationAndHolidays()
> > Dim strSql
> > Dim frm As Form
> > Dim db As DAO.Database
> > Dim rs As DAO.Recordset
> >
> > Set frm = Forms!frmCalender
> > Set db = CurrentDb
> >
> > ' Vacation YTD
> > strSql = "SELECT Count(InputID) AS TotDays FROM tblInput "
> > strSql = strSql & "WHERE ((Year([InputDate])=" & CInt(gstrYear) & ") AND
> > ((tblInput.UserID)=" & glngUserID & ") AND
> > ((tblInput.InputText)='Vacation'));"
> > Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
> > frm!txtVacYTD = rs!TotDays
> > rs.Close
> > strSql = "'"
> >
> > Set rs = Nothing
> > db.Close
> > Set db = Nothing
> > End Function
> >
> >
> > How would I count how many times the excused tardy was used for the past 6
> > months starting on the current day? Thanks!
>
Back to top
Login to vote
John Spencer

External


Since: Jan 21, 2007
Posts: 285



(Msg. 4) Posted: Fri Jul 25, 2008 9:22 am
Post subject: Re: SQL Statement help Add to elertz [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Basically in the same place you would use the function.

Instead of, for instance
=GetVacationAndHolidays()

You would use (all the following on one line)
=DCOUNT("*","TblInput","InputDate Between DateAdd(""m"",-6,Date()) and
Date() and InputText =""Excused Tardy"" ")

If you wanted to used that multiple places, you could write a very
simple VBA function

Public Function GetTardies()

'All the following on one line
GetTardies = DCOUNT("*","TblInput","InputDate Between
DateAdd(""m"",-6,Date()) and Date() and InputText =""Excused Tardy"" ")

End Function

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


Thanks wrote:
> John where would I use the DCount at?
>
> "John Spencer" wrote:
>
>> StrSQL="SELECT Count(InputID) as TotDay" & _
>> " FROM TblInput" & _
>> " WHERE InputDate Between DateAdd(""m"",-6,Date())" & _
>> " and Date() " & _
>> " and InputText =""Excused Tardy"" "
>>
>> Of course, you could simplify the whole thing by using DCount and
>> skipping the entire function
>>
>> DCOUNT("*","TblInput","InputDate Between DateAdd(""m"",-6,Date()) and
>> Date() and InputText =""Excused Tardy"" ")
>>
>> '====================================================
>> John Spencer
>> Access MVP 2002-2005, 2007-2008
>> The Hilltop Institute
>> University of Maryland Baltimore County
>> '====================================================
>>
>>
>> Chad wrote:
>>> Hello, I have a sample database I had found and wanted to change one thing.
>>> It keeps track of how many days a person had taken a "Vacation" in the
>>> current year. I would like to do a similar thing is to keep track of how many
>>> times an employee had an excused tardy within the past 6 months from the
>>> current day. The statement used to get the vacation totals is:
>>>
>>> Public Function GetVacationAndHolidays()
>>> Dim strSql
>>> Dim frm As Form
>>> Dim db As DAO.Database
>>> Dim rs As DAO.Recordset
>>>
>>> Set frm = Forms!frmCalender
>>> Set db = CurrentDb
>>>
>>> ' Vacation YTD
>>> strSql = "SELECT Count(InputID) AS TotDays FROM tblInput "
>>> strSql = strSql & "WHERE ((Year([InputDate])=" & CInt(gstrYear) & ") AND
>>> ((tblInput.UserID)=" & glngUserID & ") AND
>>> ((tblInput.InputText)='Vacation'));"
>>> Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
>>> frm!txtVacYTD = rs!TotDays
>>> rs.Close
>>> strSql = "'"
>>>
>>> Set rs = Nothing
>>> db.Close
>>> Set db = Nothing
>>> End Function
>>>
>>>
>>> How would I count how many times the excused tardy was used for the past 6
>>> months starting on the current day? Thanks!
Back to top
Login to vote
Display posts from previous:   
       Home -> Office other -> Getting Started All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
 Office
  Office Other
 Security
 WinRAR
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET