I have a crosstab query called ShiftHours in access with the following fields:
Staff, Shift, Mon, Tue, Wed, Thu, Fri, Sat, Sun
i need to export the fields to excel using a recordset
the problem i have is the the shift field
i need to loop through the records and if the shift = "AM" then update specified cells in excel
elseif shift = PM then update the other cells
below is the code i've been working on
Dim rs9 As Recordset
Set rst9 = CurrentDb.OpenRecordset("ShiftHours")
Do While Not rst9.EOF
For X = 10 To 16
'Am
If DLookup("Shift", "ShiftHours", "[Shift] = AM") Then
Set xlSheet = xlBook.Worksheets("Labor")
xlSheet.Range("a" & X) = (rst9.[Employee])
xlSheet.Range("c" & X) = (rst9.[Rate])
xlSheet.Range("d" & X) = (rst9.[wed])
xlSheet.Range("h" & X) = (rst9.[thu])
xlSheet.Range("l" & X) = (rst9.[fri])
xlSheet.Range("p" & X) = (rst9.[sat])
xlSheet.Range("t" & X) = (rst9.[sun])
xlSheet.Range("x" & X) = (rst9.[mon])
xlSheet.Range("ab" & X) = (rst9.[tue])
'PM
else
xlSheet.Range("a" & X) = (rst9.[Employee])
xlSheet.Range("c" & X) = (rst9.[Rate])
xlSheet.Range("f" & X) = (rst9.[wed])
xlSheet.Range("j" & X) = (rst9.[thu])
xlSheet.Range("o" & X) = (rst9.[fri])
xlSheet.Range("r" & X) = (rst9.[sat])
xlSheet.Range("t" & X) = (rst9.[sun])
xlSheet.Range("z" & X) = (rst9.[mon])
xlSheet.Range("ad" & X) = (rst9.[tue])
End If
rst9.MoveNext
Next X
Loop
xlBook.Save
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Staff, Shift, Mon, Tue, Wed, Thu, Fri, Sat, Sun
i need to export the fields to excel using a recordset
the problem i have is the the shift field
i need to loop through the records and if the shift = "AM" then update specified cells in excel
elseif shift = PM then update the other cells
below is the code i've been working on
Dim rs9 As Recordset
Set rst9 = CurrentDb.OpenRecordset("ShiftHours")
Do While Not rst9.EOF
For X = 10 To 16
'Am
If DLookup("Shift", "ShiftHours", "[Shift] = AM") Then
Set xlSheet = xlBook.Worksheets("Labor")
xlSheet.Range("a" & X) = (rst9.[Employee])
xlSheet.Range("c" & X) = (rst9.[Rate])
xlSheet.Range("d" & X) = (rst9.[wed])
xlSheet.Range("h" & X) = (rst9.[thu])
xlSheet.Range("l" & X) = (rst9.[fri])
xlSheet.Range("p" & X) = (rst9.[sat])
xlSheet.Range("t" & X) = (rst9.[sun])
xlSheet.Range("x" & X) = (rst9.[mon])
xlSheet.Range("ab" & X) = (rst9.[tue])
'PM
else
xlSheet.Range("a" & X) = (rst9.[Employee])
xlSheet.Range("c" & X) = (rst9.[Rate])
xlSheet.Range("f" & X) = (rst9.[wed])
xlSheet.Range("j" & X) = (rst9.[thu])
xlSheet.Range("o" & X) = (rst9.[fri])
xlSheet.Range("r" & X) = (rst9.[sat])
xlSheet.Range("t" & X) = (rst9.[sun])
xlSheet.Range("z" & X) = (rst9.[mon])
xlSheet.Range("ad" & X) = (rst9.[tue])
End If
rst9.MoveNext
Next X
Loop
xlBook.Save
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing