Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count records in recordset

Status
Not open for further replies.

coyote69

Technical User
Feb 19, 2002
45
US
I get a syntax error what am i missing

table is contactmanager
field to count is apptdates


Private Sub apptcheck2()
Dim db As Database
Dim rs As Recordset

Dim sqlstring As String

Set db =OpenDatabase("c:\data\op\pos405\contact2\contactmanager.mdb")

searchfor = InputBox("Enter appt date")



sqlstring = "Select contactmanager.apptdate, count(contactmanager.apptdate)As
NoOfOrders from contactmanager and having ((contactmanager.apptdate) = #" & searchfor & "#"

Set rs = db.OpenRecordset(sqlstring)

picResults.Print rs.Fields(" noOfdates ")

End Sub
 
try axing the AND from your SQL and see if that clears it up. I would also replace HAVING with WHERE. I think that's what you're after.

so:

sqlstring = "SELECT contactmanager.apptdate, count(contactmanager.apptdate) AS NoOfOrders FROM contactmanager WHERE (contactmanager.apptdate) = #" & searchfor & "#"


:)
paul
penny1.gif
penny1.gif
 
I now get an error that I am trying to execute a query that does not include the specified expression apptdate as part of an aggregrate expression
 
Try this..


sqlstring = "Select contactmanager.apptdate, count(contactmanager.apptdate) As NoOfOrders from contactmanager and having ((contactmanager.apptdate) = #" & searchfor & "#)"

* I just inswereted a space bet. "apptdate)" and "As",
Then close bracket after "#".

my 2 cents.
 
Still the same problem. Syntax problems give me a headache
 
Try this

sqlstring = "SELECT contactmanager.apptdate, count(contactmanager.apptdate) AS NoOfOrders FROM contactmanager WHERE contactmanager.apptdate = #" & searchfor & "# Group By contactmanager.appdate"

 
In case you just copied and pasted the code, that "group by" clause should have the field name changed from "appdate" to "apptdate" - there's a typo in there.
 
If only it was that easy. that did not help it any I still get a syntax error. Thanks for the good observation though.
 
Are you sure that the data in the "searchfor" variable is in a valid date format? I tested the SQL directly in Access and it works fine, but I did hard code the date (obviously, since I was directly in an Access query window). I used #8/5/2001# for the date.
 
I tried that also and now i am getting a type mismatch error
 
everybody here have there own imagination of what really is happening to your SQL statement..

Maybe it would help if you can send me the table with the data... just the "contactmanager" table in one database, and i'll figure it out...

ega.

ega4htm@yahoo.com
 
I tried this with youre table and it worked...

"SELECT Format([contactmanager].[ApptDate],"mm/dd/yy") AS Expr1, Count(contactmanager.ApptDate) AS NoOfOrders FROM contactmanager
GROUP BY Format([contactmanager].[ApptDate],"mm/dd/yy")
HAVING (((Format([contactmanager].[ApptDate],"mm/dd/yy"))=#" searchfor & "#))"


- searchfor is assumed to be formated as "mm/dd/yy".
- you need to use the format function because your AppDate Field contains trailing time.

If you equate #12/31/02 10:00:00 AM# with #12/31/02", it will be always false....

good luck!

..you mentioned that you need help regarding combobox, please start a new thread.

cheers,
ega

cheers,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top