Link to home
Start Free TrialLog in
Avatar of shieldsco
shieldscoFlag for United States of America

asked on

Access VBA Fill Record with Previous Value

I have a table with five fields. I would like to fill the next blank records automatically with values from the previous record. Can you help with the code. Thanks
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

I know you asked for code, which I don't have enough information to write. Meanwhile, you can press Ctrl-' (single quote) to copy the value from the field of the previous record. btw, this works in Excel too :)

out of curiosity, why are you copying values?
Avatar of shieldsco

ASKER

It's an csv import file
OOPS! I accidentally gave you Excel code ... need more information to write for Access:
1. What are the fieldnames?
2. And are you using a form to look at data (tables can't have code)

I decided to leave this in here anyway...
assuming you are in a blank row , you can run this code, which will need to be stored in another workbook, like your Personal Macro Workbook since CSV files can't have code:
Sub CopyPreviousValues_Col_AtoE()
'160902
   Dim nRow As Long
   nRow = ActiveCell.Row
   With ActiveSheet
      .Cells(nRow, 1) = .Cells(nRow - 1, 1)
      .Cells(nRow, 2) = .Cells(nRow - 1, 2)
      .Cells(nRow, 3) = .Cells(nRow - 1, 3)
      .Cells(nRow, 4) = .Cells(nRow - 1, 4)
      .Cells(nRow, 5) = .Cells(nRow - 1, 5)
   End With

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial