Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21238

Object doesn't support this property or method while exporting data to excel.

$
0
0
Hello,

I need a little help with this.

I am exporting data from my access database to an excel and I am getting the error "Object doesn't support this property or method".

Below is my code.

I have also indicated the line that throws the error.

I was wondering if it was due to incorrect code as the error does not point to the same lines which have been used above.


============================================
Code
============================================

Private Sub btnGenerate_Click()
rs.Open "Select * from Users where Team='" & team & "'", cn, adOpenKeyset, adLockOptimistic
rs1.Open "Select* from LoginRecords where EmpID='" & rs.Fields(0) & "' order by SDate asc", cn, adOpenKeyset, adLockOptimistic
xl.Workbooks.Open "C:\Allowance.xlsm"
counter = 0
smonthName = cmbMonth.Text
imonthno = Month(CDate("01, " & smonthName & " 2013"))
xl.ActiveWorkbook.Sheets(2).Cells(8, 3) = imonthno
For i = 0 To rs.RecordCount - 1
xl.ActiveWorkbook.Sheets(2).Cells(20 + i, 2).Value = rs.Fields(0) |
xl.ActiveWorkbook.Sheets(2).Cells(20 + i, 3).Value = rs.Fields(4) |----------------> I dont see the error in these three lines.
xl.ActiveWorkbook.Sheets(2).Cells(20 + i, 4).Value = rs.Fields(6) |
If rs1.EOF = True Then
xl.ActiveWorkbook.Sheets(2).Cell(20, 3).Value = "H"
Else
For j = 0 To rs1.RecordCount - 1 Step 2
xl.ActiveWorkbook.Sheets(2).Cell(20 + i, 3).Value = rs1.Fields(5) --------------> This is the line where I get the error.
List1.AddItem rs1.Fields(5)
rs1.MoveNext
Next
End If
rs.MoveNext
Next
xl.ActiveWorkbook.SaveAs "C:\" & team & " Shift Allowance " & cmbMonth.Text & " " & Year(Now) & ".xlsm"
xl.ActiveWorkbook.Close
xl.Workbooks.Close
xl.Quit
MsgBox "Report successfully generated for " & cmbMonth.Text & " " & Year(Now) & "", vbOKOnly + vbInformation
Set xl = Nothing
Set rs = Nothing
Set rs1 = Nothing
End Sub

============================================
End of Code
============================================

Please let me know if there is anything wrong with the code which might have triggered the error.

Any help on this will be greatly appreciated.

Thanks.

Viewing all articles
Browse latest Browse all 21238

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>