philfer
02-09-2018, 04:15 AM
Hi,
I am doing a copyfromrecordset action in VBA. The recordset had data in it and it drops the data into the worksheet but then I get a "3021 no current record" error
My code is below. Does anyone have any idea why this is happening?
Set objWS = objWB.Worksheets("Total Stock")
With objWS
'get the stock list
Set MyRst = MyDB.OpenRecordset("qryAllStock")
MyRst.MoveLast
RcdCount = MyRst.RecordCount
MyRst.MoveFirst
'only add the following if there are records to export
If RcdCount > 0 Then
.Range("totalstock").Offset(1, 0).CopyFromRecordset MyRst
.Columns("I:I").NumberFormat = "#,##0.00"
.Columns("C:C").NumberFormat = "#,##0.000"
.Columns("H:H").NumberFormat = "#,##0.000"
.Columns("L:M").NumberFormat = "#,##0.000"
End If
End With
Set objWS = Nothing
I am doing a copyfromrecordset action in VBA. The recordset had data in it and it drops the data into the worksheet but then I get a "3021 no current record" error
My code is below. Does anyone have any idea why this is happening?
Set objWS = objWB.Worksheets("Total Stock")
With objWS
'get the stock list
Set MyRst = MyDB.OpenRecordset("qryAllStock")
MyRst.MoveLast
RcdCount = MyRst.RecordCount
MyRst.MoveFirst
'only add the following if there are records to export
If RcdCount > 0 Then
.Range("totalstock").Offset(1, 0).CopyFromRecordset MyRst
.Columns("I:I").NumberFormat = "#,##0.00"
.Columns("C:C").NumberFormat = "#,##0.000"
.Columns("H:H").NumberFormat = "#,##0.000"
.Columns("L:M").NumberFormat = "#,##0.000"
End If
End With
Set objWS = Nothing