(Msg. 1) Posted: Sat Aug 16, 2008 10:29 pm
Post subject: VBA SQL statement help Archived from groups: microsoft>public>access>gettingstarted (more info?)
Hello, I am trying to figure out how to write a sql statement that will count
how many times excused absence was used within the past 6 months starting on
todays date. I wrote the statement below but it doesnt give me any results?
What am I missing? Thanks!
Public Function GetVacationAndHolidays()
Dim strSql
Dim frm As Form
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set frm = Forms!frmCalendar
Set db = CurrentDb
'TEST
strSql = "SELECT Count(tblInput.InputID) AS TotDays FROM tblInput "
strSql = strSql & "WHERE tblInput.InputDate = >DateAdd('M',-6,Date())
And tblInput.UserID = 2 AND ((tblInput.InputText)='Excused Absence';"
Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
frm!txtTEST = rs!TotDays
rs.Close
strSql = "'"
Set rs = Nothing
db.Close
Set db = Nothing
End Function
(Msg. 2) Posted: Sun Aug 17, 2008 7:49 am
Post subject: Re: VBA SQL statement help [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
Personally, I'd use DCOUNT to do this. It is optimized for this type of
thing, and requires a lot less code.
Public Function GetExcusedAbsense(intUserID) as integer
If you insist on using your code, then you neen to move the DateAdd( )
function outside of the quotes, and set it off with # symbols (as I did
above). Other than that, I think your code looks about right.
HTH
Dale
"SoggyCashew" <SoggyCashew.TakeThisOut@discussions.microsoft.com> wrote in message
news:EA2A5369-9A4B-4F07-9C83-2787617A9355@microsoft.com...
> Hello, I am trying to figure out how to write a sql statement that will
> count
> how many times excused absence was used within the past 6 months starting
> on
> todays date. I wrote the statement below but it doesnt give me any
> results?
> What am I missing? Thanks!
>
> Public Function GetVacationAndHolidays()
> Dim strSql
> Dim frm As Form
> Dim db As DAO.Database
> Dim rs As DAO.Recordset
>
> Set frm = Forms!frmCalendar
> Set db = CurrentDb
>
> 'TEST
> strSql = "SELECT Count(tblInput.InputID) AS TotDays FROM tblInput "
> strSql = strSql & "WHERE tblInput.InputDate = >DateAdd('M',-6,Date())
> And tblInput.UserID = 2 AND ((tblInput.InputText)='Excused Absence';"
> Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
> frm!txtTEST = rs!TotDays
> rs.Close
> strSql = "'"
>
>
> Set rs = Nothing
> db.Close
> Set db = Nothing
> End Function
>
>
>
> --
> Thanks,
> Chad
(Msg. 3) Posted: Sun Aug 17, 2008 7:49 am
Post subject: Re: VBA SQL statement help [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
Dale, Im going to have to go with what I got because I have several other
text boxes with diferent names other than "Excused Absence" that im using in
this function. Im not sure I know how to do what your saying or telling me
how to fix the one I have? I tried the SQL below with no luck. It outlines
the line and sets focus to the 'M'
> Personally, I'd use DCOUNT to do this. It is optimized for this type of
> thing, and requires a lot less code.
>
> Public Function GetExcusedAbsense(intUserID) as integer
>
> Dim strCriteria as string
>
> strCriteria = "[InputDate] >= #" & DateAdd('M',-6,Date()) & "# AND " _
> & "[UserID] = " & intUserID & " AND " _
> & "[InputText]='Excused Absence'"
> GetExcusedAbsense = DCOUNT("InputID", "tblInput", strCriteria)
>
> End Function
>
> If you insist on using your code, then you neen to move the DateAdd( )
> function outside of the quotes, and set it off with # symbols (as I did
> above). Other than that, I think your code looks about right.
>
> HTH
> Dale
>
>
>
> "SoggyCashew" <SoggyCashew RemoveThis @discussions.microsoft.com> wrote in message
> news:EA2A5369-9A4B-4F07-9C83-2787617A9355@microsoft.com...
> > Hello, I am trying to figure out how to write a sql statement that will
> > count
> > how many times excused absence was used within the past 6 months starting
> > on
> > todays date. I wrote the statement below but it doesnt give me any
> > results?
> > What am I missing? Thanks!
> >
> > Public Function GetVacationAndHolidays()
> > Dim strSql
> > Dim frm As Form
> > Dim db As DAO.Database
> > Dim rs As DAO.Recordset
> >
> > Set frm = Forms!frmCalendar
> > Set db = CurrentDb
> >
> > 'TEST
> > strSql = "SELECT Count(tblInput.InputID) AS TotDays FROM tblInput "
> > strSql = strSql & "WHERE tblInput.InputDate = >DateAdd('M',-6,Date())
> > And tblInput.UserID = 2 AND ((tblInput.InputText)='Excused Absence';"
> > Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
> > frm!txtTEST = rs!TotDays
> > rs.Close
> > strSql = "'"
> >
> >
> > Set rs = Nothing
> > db.Close
> > Set db = Nothing
> > End Function
> >
> >
> >
> > --
> > Thanks,
> > Chad
>
>
>
(Msg. 4) Posted: Sun Aug 17, 2008 1:03 pm
Post subject: Re: VBA SQL statement help [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
The operator is ">=" and not "= >".
strSql = "SELECT Count(tblInput.InputID) AS TotDays FROM tblInput "
strSql = strSql & "WHERE tblInput.InputDate >= DateAdd(""M"",-6,Date())
And tblInput.UserID = 2 AND tblInput.InputText='Excused Absence' "
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
SoggyCashew wrote:
> Hello, I am trying to figure out how to write a sql statement that will count
> how many times excused absence was used within the past 6 months starting on
> todays date. I wrote the statement below but it doesnt give me any results?
> What am I missing? Thanks!
>
> Public Function GetVacationAndHolidays()
> Dim strSql
> Dim frm As Form
> Dim db As DAO.Database
> Dim rs As DAO.Recordset
>
> Set frm = Forms!frmCalendar
> Set db = CurrentDb
>
> 'TEST
> strSql = "SELECT Count(tblInput.InputID) AS TotDays FROM tblInput "
> strSql = strSql & "WHERE tblInput.InputDate = >DateAdd('M',-6,Date())
> And tblInput.UserID = 2 AND ((tblInput.InputText)='Excused Absence';"
> Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
> frm!txtTEST = rs!TotDays
> rs.Close
> strSql = "'"
>
>
> Set rs = Nothing
> db.Close
> Set db = Nothing
> End Function
>
>
>
(Msg. 5) Posted: Sun Aug 17, 2008 1:03 pm
Post subject: Re: VBA SQL statement help [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
John I get an expected: expression error at the ' before the excused absence?
--
Thanks,
Chad
"John Spencer" wrote:
> The operator is ">=" and not "= >".
>
> strSql = "SELECT Count(tblInput.InputID) AS TotDays FROM tblInput "
>
> strSql = strSql & "WHERE tblInput.InputDate >= DateAdd(""M"",-6,Date())
> And tblInput.UserID = 2 AND tblInput.InputText='Excused Absence' "
>
>
>
> '====================================================
> John Spencer
> Access MVP 2002-2005, 2007-2008
> The Hilltop Institute
> University of Maryland Baltimore County
> '====================================================
>
>
> SoggyCashew wrote:
> > Hello, I am trying to figure out how to write a sql statement that will count
> > how many times excused absence was used within the past 6 months starting on
> > todays date. I wrote the statement below but it doesnt give me any results?
> > What am I missing? Thanks!
> >
> > Public Function GetVacationAndHolidays()
> > Dim strSql
> > Dim frm As Form
> > Dim db As DAO.Database
> > Dim rs As DAO.Recordset
> >
> > Set frm = Forms!frmCalendar
> > Set db = CurrentDb
> >
> > 'TEST
> > strSql = "SELECT Count(tblInput.InputID) AS TotDays FROM tblInput "
> > strSql = strSql & "WHERE tblInput.InputDate = >DateAdd('M',-6,Date())
> > And tblInput.UserID = 2 AND ((tblInput.InputText)='Excused Absence';"
> > Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
> > frm!txtTEST = rs!TotDays
> > rs.Close
> > strSql = "'"
> >
> >
> > Set rs = Nothing
> > db.Close
> > Set db = Nothing
> > End Function
> >
> >
> >
>
(Msg. 6) Posted: Sun Aug 17, 2008 6:53 pm
Post subject: Re: VBA SQL statement help [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
"SoggyCashew" <SoggyCashew.DeleteThis@discussions.microsoft.com> wrote in message
news:FFEA2473-A7C8-465B-8E0B-7F984B2F147D@microsoft.com...
> John I get an expected: expression error at the ' before the excused
> absence?
> --
> Thanks,
> Chad
>
>
> "John Spencer" wrote:
>
>> The operator is ">=" and not "= >".
>>
>> strSql = "SELECT Count(tblInput.InputID) AS TotDays FROM tblInput "
>>
>> strSql = strSql & "WHERE tblInput.InputDate >= DateAdd(""M"",-6,Date())
>> And tblInput.UserID = 2 AND tblInput.InputText='Excused Absence' "
>>
>>
>>
>> '====================================================
>> John Spencer
>> Access MVP 2002-2005, 2007-2008
>> The Hilltop Institute
>> University of Maryland Baltimore County
>> '====================================================
>>
>>
>> SoggyCashew wrote:
>> > Hello, I am trying to figure out how to write a sql statement that will
>> > count
>> > how many times excused absence was used within the past 6 months
>> > starting on
>> > todays date. I wrote the statement below but it doesnt give me any
>> > results?
>> > What am I missing? Thanks!
>> >
>> > Public Function GetVacationAndHolidays()
>> > Dim strSql
>> > Dim frm As Form
>> > Dim db As DAO.Database
>> > Dim rs As DAO.Recordset
>> >
>> > Set frm = Forms!frmCalendar
>> > Set db = CurrentDb
>> >
>> > 'TEST
>> > strSql = "SELECT Count(tblInput.InputID) AS TotDays FROM tblInput "
>> > strSql = strSql & "WHERE tblInput.InputDate =
>> > >DateAdd('M',-6,Date())
>> > And tblInput.UserID = 2 AND ((tblInput.InputText)='Excused Absence';"
>> > Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
>> > frm!txtTEST = rs!TotDays
>> > rs.Close
>> > strSql = "'"
>> >
>> >
>> > Set rs = Nothing
>> > db.Close
>> > Set db = Nothing
>> > End Function
>> >
>> >
>> >
>>
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