Consulting

Results 1 to 3 of 3

Thread: 3021 No Current Record

  1. #1
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location

    3021 No Current Record

    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

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    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

  3. #3
    Visit following great solver as https://www.google.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •