We help IT Professionals succeed at work.

simpler way to write this code for reading records from Access and posting to excel worksheet

195 Views
Last Modified: 2017-10-30
Excel vba
Access

I have a bit of code that is reading a recordset from Access.

While Not Rec.EOF

  cell.Offset(0, 30).Value = Rec.Fields(1)
  cell.Offset(0, 31).Value = Rec.Fields(2)
  cell.Offset(0, 32).Value = Rec.Fields(3)
  cell.Offset(0, 33).Value = Rec.Fields(4)
  cell.Offset(0, 34).Value = Rec.Fields(5)
  cell.Offset(0, 35).Value = Rec.Fields(6)
  cell.Offset(0, 36).Value = Rec.Fields(7)
  cell.Offset(0, 37).Value = Rec.Fields(8)
  cell.Offset(0, 38).Value = Rec.Fields(9)
  cell.Offset(0, 39).Value = Rec.Fields(10)
  cell.Offset(0, 40).Value = Rec.Fields(11)
  cell.Offset(0, 41).Value = Rec.Fields(12)
  cell.Offset(0, 42).Value = Rec.Fields(13)
  cell.Offset(0, 43).Value = Rec.Fields(14)
  cell.Offset(0, 44).Value = Rec.Fields(15)

Rec.MoveNext
Wend

Rec.Close

Open in new window


I'm starting (to post) at a certain cell on the worksheet and a field(from access)

I'm gonna have 55 fields to fill the cells in Excel.

is there a simpler way to write this code for reading records from Access and posting to excel worksheet?

Thanks
fordraiders
Comment
Watch Question

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Bill, Thanks seems so simple!
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
thanks very much !!!