Select sum() query

G

Guest

the following statement

strSQL = "select sum(leavehours) as retval from tblempleave where empid = " & Me.boxEmpID & " and leavetype = " & Me.boxLeaveType & "

returns a strSQL value of "select sum(leavehours) as retval from tblempleave where empid = 000001111 and leavetype = s

DoCmd.RunSQL strSQ

returns a runtime error '2342': A RunSQL action requires an argument consisting of an SQL statement

what am I missing here

tia
JMorrell
 
C

Chris

Well, the DoCmd.RunSQL is meant to execute action queries,
INSERT, DELETE,UPDATE queries.

What do you want to do with the sum?
Also, your SQL statement is wrong. Is EmpID a numeric?
It looks like a text with the leading zeros. If it's
numeric, leave that part alone, otherwise:

strSQL = "select sum(leavehours) as retval from
tblempleave where empid = '" & Me.boxEmpID & "' and
leavetype = '" & Me.boxLeaveType & "'"

Eitherway, LeaveType is text and needs quotes around the
value.

Have checked into the DSUM function?

dim sngLeave as Single
sngLeave = DSum("LeaveHours","tblEmpLeave","empid = '" &
Me.boxEmpID & "' and leavetype = '" & Me.boxLeaveType
& "'")


Chris


-----Original Message-----
the following statement:

strSQL = "select sum(leavehours) as retval from
tblempleave where empid = " & Me.boxEmpID & " and
leavetype = " & Me.boxLeaveType & ""
returns a strSQL value of "select sum(leavehours) as
retval from tblempleave where empid = 000001111 and
leavetype = s"
DoCmd.RunSQL strSQL

returns a runtime error '2342': A RunSQL action requires
an argument consisting of an SQL statement.
 
G

Guest

----- Chris wrote: ----

Well, the DoCmd.RunSQL is meant to execute action queries,
INSERT, DELETE,UPDATE queries

What do you want to do with the sum
Also, your SQL statement is wrong. Is EmpID a numeric?
It looks like a text with the leading zeros. If it's
numeric, leave that part alone, otherwise

strSQL = "select sum(leavehours) as retval from
tblempleave where empid = '" & Me.boxEmpID & "' and
leavetype = '" & Me.boxLeaveType & "'

Eitherway, LeaveType is text and needs quotes around the
value

Have checked into the DSUM function

dim sngLeave as Singl
sngLeave = DSum("LeaveHours","tblEmpLeave","empid = '" &
Me.boxEmpID & "' and leavetype = '" & Me.boxLeaveType
& "'"


Chri


-----Original Message----
the following statement
tblempleave where empid = " & Me.boxEmpID & " and
leavetype = " & Me.boxLeaveType & "retval from tblempleave where empid = 000001111 and
leavetype = s

I'll be checking the retval against other values. empid is a text field (SSN)
Can't the DoCmd.RunSQL just return a value based on the query

the dsum() works for what I want. Thank you. But I'm still curious...
 
D

Douglas J. Steele

JMorrell said:
I'll be checking the retval against other values. empid is a text field (SSN).
Can't the DoCmd.RunSQL just return a value based on the query?

the dsum() works for what I want. Thank you. But I'm still curious...

No, it can't. As Chris mentioned, RunSQL is only for Action queries.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Using Date fields in SQL 2
Stop Query 4
Running a SELECT statement 2
Error on DoCmd.RunSQL 3
SQL Query in VBA 9
Open select query in vba code 4
SQL -- VBA 3
DoCmd.RunSQL 8

Top