How to automate copying data from previous record to the current

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

All, I have a table that has missing values for fields. I would like to know
how to copy the contents of fields from a previous record to the current one.
I attempted to do it in an update query but was unsuccessful. Also tried to
create a macro that invoke <CTRL> <'> but that didn't work either. Any
suggestions would be appreciated. The table has thousands of records so
manually copying the fields would be prohibitive.
 
All, I have a table that has missing values for fields. I would
like to know how to copy the contents of fields from a previous
record to the current one.
I attempted to do it in an update query but was unsuccessful.
Also tried to
create a macro that invoke <CTRL> <'> but that didn't work either.
Any suggestions would be appreciated. The table has thousands of
records so manually copying the fields would be prohibitive.

you could use a recordset,
storing each field to a variable if the field is not null, and
writing from the variable if the field is null
The code below is untested, and needs to be adjusted to your table


dim rs as dao.recordset
set rs= currentdb.openrecordset("SELECT * from table order by
?????")
dim FldCount as integer
dim FldPointer as integer
dim fieldvalues(FldCount)
do while not rs.eof
For fldPointer = 0 to FldCount - 1
if isnull(rs!fields(fldpointer)
fieldvalues(fldPointer) = rs!fields(fldpointer)
else
rs!fields(fldpointer) = fieldvalues(fldPointer)
end if
next fldpointer
loop
 
In Datasheet View, Ctrl+' should work. It does for me in all versions. I
cannot check Office 2007 right now.
 
All, I have a table that has missing values for fields. I would like to know
how to copy the contents of fields from a previous record to the current one.
I attempted to do it in an update query but was unsuccessful. Also tried to
create a macro that invoke <CTRL> <'> but that didn't work either. Any
suggestions would be appreciated. The table has thousands of records so
manually copying the fields would be prohibitive.


you could use a recordset,
storing each field to a variable if the field is not null, and writing
from the variable if the field is null
The code below is untested, and needs to be adjusted to your table


dim rs as dao.recordset
set rs= currentdb.openrecordset("SELECT * from table order by ?????")
dim FldCount as integer
dim FldPointer as integer
FldCount = rs.fields.count
dim fieldvalues(FldCount)
do while not rs.eof
For fldPointer = 0 to FldCount - 1
if isnull(rs!fields(fldpointer)
fieldvalues(fldPointer) = rs!fields(fldpointer)
else
rs!fields(fldpointer) = fieldvalues(fldPointer)
end if
next fldpointer
loop
 
Bob Quintal said:
you could use a recordset,
storing each field to a variable if the field is not null, and
writing from the variable if the field is null
The code below is untested, and needs to be adjusted to your table


dim rs as dao.recordset
set rs= currentdb.openrecordset("SELECT * from table order by
?????")
dim FldCount as integer
dim FldPointer as integer
dim fieldvalues(FldCount)
do while not rs.eof
For fldPointer = 0 to FldCount - 1
if isnull(rs!fields(fldpointer)
fieldvalues(fldPointer) = rs!fields(fldpointer)
else
rs!fields(fldpointer) = fieldvalues(fldPointer)
end if
next fldpointer
loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top