PDA

View Full Version : 3021 No Current Record



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

OBP
02-09-2018, 07:39 AM
I would use a For/Next loop ie
For count = 1 to RcdCount
.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"
Next count

zlatanlex24
02-12-2018, 12:03 PM
Visit following great solver as https://www.google.com/