View Full Version : error in SqlStr so they tell no Current record


Ntwobike
03-24-2008, 02:12 AM
Dim myxls

Dim myworkbook
Dim myworkseet
Dim rts As Recordset
Dim rtsBreak As Recordset
Dim irow As Integer
Dim tbl As DAO.TableDef
Dim istbl As Boolean
Dim SqlStr As String


Set myxls = CreateObject("Excel.Application")

myxls.Visible = True
Set myworkbook = myxls.workbooks.Open("C:\Documents and Settings\Administrator\Desktop\shasika\attendancex ls.xlsx")
Set myworksheet = myworkbook.Worksheets("Sheet1")

Set rts = CurrentDb.OpenRecordset("Query_for_attendance")
Set rts = CurrentDb.OpenRecordset("Worked_hrs")
Set rts = CurrentDb.OpenRecordset("Break_out")

CurrentDb.Execute ("DROP TABLE forexcel")
CurrentDb.Execute ("DROP TABLE calculateBreakstime")

CurrentDb.Execute ("maketbltoexcel")
CurrentDb.Execute ("calculate break outs")

Set rts = CurrentDb.OpenRecordset("SELECT * FROM forexcel")



irow = 2
myworksheet.Cells(1, 1).Value = "EmpCode"
myworksheet.Cells(1, 2).Value = "AttDate"
myworksheet.Cells(1, 3).Value = "Chekin"
myworksheet.Cells(1, 4).Value = "Checkout"
myworksheet.Cells(1, 5).Value = "Workedhrs"
myworksheet.Cells(1, 6).Value = "NoOfBreaks"

Do While Not rts.EOF
myworksheet.Cells(irow, 1).Value = rts!empCode
myworksheet.Cells(irow, 2).Value = rts!AttDate
SqlStr = "SELECT * " & "FROM [calculateBreakstime] WHERE ([EmpCode]" & " = '" & rts!empCode & "')"

Set rtsBreak = CurrentDb.OpenRecordset(SqlStr)
myworksheet.Cells(irow, 7).Value = rtsBreak!empCode
myworksheet.Cells(irow, 3).Value = rts!Chekin
myworksheet.Cells(irow, 4).Value = rts!Checkout
myworksheet.Cells(irow, 6).Value = rts!NoOfBreaks

myworksheet.Cells(irow, 5).Value = (DateDiff("h", rts!Chekin, rts!Checkout)) & ":" & (DateDiff("n", rts!Chekin, rts!Checkout)) Mod 60
irow = irow + 1
rts.MoveNext

Loop

jzwp22
03-24-2008, 06:15 AM
This should work if rts!empCode is a text field
SqlStr = "SELECT * FROM [calculateBreakstime] WHERE ([EmpCode] = '" & rts!empCode & "')"

If rts!empCode is a numeric field this should work (numeric fields are not set off by single apostrophes)

SqlStr = "SELECT * FROM [calculateBreakstime] WHERE ([EmpCode] = " & rts!empCode & ")"