473,503 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filling in null fields from previous records

Hello,

I have a table that has null fields that need to be filled in with the value of the previous record
(example below)

id date
1 2/2/02
2
3 4/4/02
4
5
6 3/303
7

What I need to do is loop through the records and if the filed is null--insert the value of the
rprevious record into it. There may be one null or there may be many. I don't have a clear
understanidng of loops--can this be done? I inherited this dataset and need to clean it up--there
are 6,000 records in this table that I need to fix. I need to do it for different fields but used
the date field as the example

Thanks
bob
Nov 13 '05 #1
1 3868
al*****@cox.net wrote in message news:<40***************@news.west.cox.net>...
Hello,

I have a table that has null fields that need to be filled in with the value of the previous record
(example below)

id date
1 2/2/02
2
3 4/4/02
4
5
6 3/303
7

What I need to do is loop through the records and if the filed is null--insert the value of the
rprevious record into it. There may be one null or there may be many. I don't have a clear
understanidng of loops--can this be done? I inherited this dataset and need to clean it up--there
are 6,000 records in this table that I need to fix. I need to do it for different fields but used
the date field as the example

Thanks
bob


Bob,
here's an example that uses a date field.

Option Compare Database
Option Explicit
Public Sub FillInTheBlanks()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim dtLast As Date

Set db = CurrentDb
Set rs = db.OpenRecordset("tblDates", dbOpenTable)
rs.MoveFirst '--Go to the first record
dtLast = rs.Fields("DateDue").Value '--stuff the date into a
variable
rs.MoveNext '--go to the next record

Do Until rs.EOF
If IsNull(rs.Fields("DateDue")) Then
rs.Edit '--put record in edit
mode.
rs.Fields("DateDue") = dtLast '--assign the new date
value from the previous record.
rs.Update '--save the new date to
the record
Else
dtLast = rs.Fields("DateDue") '--if the new record's
value is not null, save it to write to the next blank date
End If
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
Set db = Nothing

MsgBox "Done! "
End Sub
If you wanted, you could probably change it so that the dtLast
variable to a Variant type, so you could put any kind of value in
there. then just pass the field you want to update and the tablename,
and you could make it really generic. (If you really wanted to go to
town, you could create a table of tables and fields that need to be
updated, loop through that, and pass the values to this Sub...)
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
4018
by: AFN | last post by:
I am running the code below to generate XML from a data table. But some fields in the data table are Null for every record. Suppose field5 has a null database value. I would expect to see: ...
6
5254
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
1
2883
by: allyn44 | last post by:
Hello--i have inherited a dataset that has records like below: id locationid 1 7 2 3 5 4 5 6 4
3
4002
by: JOEP | last post by:
What do I need to do to allow an append query to post null values to records in a field of the destination table? Basically I want to allow records with null values to post to the table. The append...
1
2265
by: RiesbeckP | last post by:
Hi All, I have a DB where there are customer numbers and a few other fields. I want to be able to pull all of the null records for a particular field as well as all the other customer numbers...
6
17139
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how...
1
2742
by: VMI | last post by:
I need to display Access data in a datagrid but the Access table has over 2 million records. Since I can't fill a datatable with all those records but the user needs to see all of them, how can I...
3
1992
by: crjunk | last post by:
I have a 3 table in my DataSet that I'm filling with data. After I've filled these 3 tables, I'm then trying to run a query that will fill a 4th table in the DataSet with data from the three...
7
1892
by: MLH | last post by:
But now here's the catch - I want to see information from an earlier record in the table. Suppose the correspondence table had these five records ID VehicleJobID OutDate OutType 1 ...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.