rjbuckley
asked on
query works but cnn.execute does not?
sqlstring = "SELECT DateDiff(" & Chr(34) & "n" & Chr(34) & ",[timeout],[time63]) AS ElapsedTime, VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut INTO tblTemp " & _
"FROM VehicleClosed GROUP BY DateDiff(" & Chr(34) & "n" & Chr(34) & ",[timeout],[time63]), VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut, VehicleClosed.IncidentID, VehicleClosed.Time63 " & _
"HAVING VehicleClosed.Town=" & Chr(34) & Me.Town.Column(1) & Chr(34) & " AND VehicleClosed.Vehicle Like " & Chr(34) & Me.Vehicle & Chr(34) & " AND (VehicleClosed.DateOut Between " & Chr(34) & DateRange & Chr(34) & ") AND VehicleClosed.Time63 <>''"
This is the debug.print of my sqlstring query:
'SELECT DateDiff("n",[timeout],[ti me63]) AS ElapsedTime, VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut INTO tblTemp FROM VehicleClosed GROUP BY DateDiff("n",[timeout],[ti me63]), VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut, VehicleClosed.IncidentID, VehicleClosed.Time63 HAVING VehicleClosed.Town="SEYMOU R" AND VehicleClosed.Vehicle Like "?-*" AND (VehicleClosed.DateOut Between "04/01/2004" AND "04/28/2004") AND VehicleClosed.Time63 <>''
If I paste the debug.print into a Query (SQL View) it works fine. In VBA it does not return records. Any ideas?
Thanks,
Rich
"FROM VehicleClosed GROUP BY DateDiff(" & Chr(34) & "n" & Chr(34) & ",[timeout],[time63]), VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut, VehicleClosed.IncidentID, VehicleClosed.Time63 " & _
"HAVING VehicleClosed.Town=" & Chr(34) & Me.Town.Column(1) & Chr(34) & " AND VehicleClosed.Vehicle Like " & Chr(34) & Me.Vehicle & Chr(34) & " AND (VehicleClosed.DateOut Between " & Chr(34) & DateRange & Chr(34) & ") AND VehicleClosed.Time63 <>''"
This is the debug.print of my sqlstring query:
'SELECT DateDiff("n",[timeout],[ti
If I paste the debug.print into a Query (SQL View) it works fine. In VBA it does not return records. Any ideas?
Thanks,
Rich
dates in access should be enclosed by # and not by "
Try encapsulating the times with # rather than "
ASKER
I get that, but why does it work in the query and not in VBA?
sorry angel - you are too fast for me
The query translates the query before submitting it to jet - it assumes that a date field is a date and changes it to the default date format - submitting to a conn it is not translated
ASKER
Here's the run. The guy that created the database made all the fields text. It is not a date field. I could not get the # to work.
You cant use text with between - translate the string date function to a date and it should work - ie cdate(VehicleClosed.DateOu t) Between #04/01/2004# AND #04/28/2004#
Obviously access is assuming because you are using the between keyword you need to change the figures to numbers
Obviously access is assuming because you are using the between keyword you need to change the figures to numbers
ASKER
I will try it. I thought that I had, but I may be confused.....
ASKER
This is the debug. It still does not put records in the table.....
SELECT DateDiff("n",[timeout],[ti me63]) AS ElapsedTime, VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut INTO tblTemp FROM VehicleClosed GROUP BY DateDiff("n",[timeout],[ti me63]), VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut, VehicleClosed.IncidentID, VehicleClosed.Time63 HAVING VehicleClosed.Town="SEYMOU R" AND VehicleClosed.Vehicle Like "?-*" AND (cdate(VehicleClosed.DateO ut) Between #04/01/2004# AND #04/28/2004#) AND VehicleClosed.Time63 <>''
SELECT DateDiff("n",[timeout],[ti
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SELECT DateDiff("n",[timeout],[ti me63]) AS ElapsedTime, VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut INTO tblTemp FROM VehicleClosed GROUP BY DateDiff("n",[timeout],[ti me63]), VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut, VehicleClosed.IncidentID, VehicleClosed.Time63 HAVING VehicleClosed.Town="SEYMOU R" AND VehicleClosed.Vehicle Like "?-%" AND (cdate(VehicleClosed.DateO ut) Between #04/01/2004# AND #04/28/2004#) AND VehicleClosed.Time63 <>''
Does not work either......
Does not work either......
ASKER
But a Query with the try before the last one still does.
You are talking about putting records in the table - is this part of an insert statement? or is this teh full sql?
ASKER
It is a Select ...Into. If this won't work in VBA can I use the Query and pass parameters to it from VBA. How would you do that. I need to pass Town, DateRange, and Vehicle.
Is the attempt to execute this query via the ADO connection object causing an error?, you could examine the Errors collection of the connection object to see if anything has gone awry! This may give some clue as to why it does'nt work with ADO.
ASKER
No errors. The Query returns 3 rows, the ADO returns 0 rows. The ADO does create the table, but there are no records.
I'm thinking that you do not need the ado connection.
Can you put the two below lines after the select part of the statement - where strBackupLocation is the location of the db
"INTO VehicleClosed" & vbCrLf & _
"IN" & chr(34) & strBackupLocation & vbCrLf & chr(34) & _
And then do
DoCmd.RunSQL sqlString
Can you put the two below lines after the select part of the statement - where strBackupLocation is the location of the db
"INTO VehicleClosed" & vbCrLf & _
"IN" & chr(34) & strBackupLocation & vbCrLf & chr(34) & _
And then do
DoCmd.RunSQL sqlString
'SELECT DateDiff("n",[timeout],[ti me63]) AS ElapsedTime, VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut INTO tblTemp FROM VehicleClosed GROUP BY DateDiff("n",[timeout],[ti me63]), VehicleClosed.Town, VehicleClosed.Vehicle, VehicleClosed.DateOut, VehicleClosed.IncidentID, VehicleClosed.Time63 HAVING VehicleClosed.Town="SEYMOU R" AND VehicleClosed.Vehicle Like "?-*" AND (VehicleClosed.DateOut Between "04/01/2004" AND "04/28/2004") AND VehicleClosed.Time63 <>''
What's the deal with the last set (or single) quotes?????? This is your debug printout. A single apostrophe appears at the beginning of the code ('Select)- and assuming the last one is it's partner - you are missing a quote in the VehicleClosed.Time63 <> ' ????
Scott C
What's the deal with the last set (or single) quotes?????? This is your debug printout. A single apostrophe appears at the beginning of the code ('Select)- and assuming the last one is it's partner - you are missing a quote in the VehicleClosed.Time63 <> ' ????
Scott C
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try breaking the Query up into smaller chunks testing each with ADO to see if there's a difference. I don't see any ADO code in any of your previous postings, so i'm not sure what you're trying to achieve!