Update query to fill blank fields with corresponded value

George82

Registered User.
Local time
Today, 13:37
Joined
Dec 8, 2011
Messages
15
I am relatively new to Access and I want to make an update query that will fill blank records of a field with the corresponded value based on another field.

Let me give an example to understand what I mean.

Table:
ID
COLOR
0025
black
0036
white
0074
red
0025 "blank"

0025
"blank"
0036
"blank"

If I enter in “ID” field the same value as above, see “0025 & 0036” I want the expected result to be:

Table:
ID
COLOR
0025
black
0036
white
0074
red
0025
black
0025
black
0036
white

I tried to do this with the following:
DLookUp("COLOR";"table name";"ID=" & [ID])
But sometimes it fills blank records with values and sometimes it turns records with values to blanks.
How can I ensure that only blank records will be field and not the other way around?

Any help will be much appreciated.
Thanks.
 
Last edited:
Thank you for your reply.

I used Nz function and set “Color” is NOT NULL, but what it does now is turn the records with values to blanks.

Ps. “Color” I used to describe my example. Those are not the actual names of my fields.
 
What I gave you wasn't the exact syntax. It was only to point you in the right direction:
Code:
Nz([Color], DLookUp("COLOR";"table name";"ID=" & [ID] & " AND Not [Color] Is Null"))
 
George82,
For this to work you need to organize your data into two tables. The color table will have "ColorID as an autonumber field, "ColorCode" as text because of the leading zeros, and "Color" which has the names. Something like this.
ColorID ColorCode Color
1 0025 Black
2 0036 White
In the other table that has the data, you should have a ColorID field as a long integer with the 1,2,3, numbers there. Then, a simple query with both tables in it and a line drawn between the two ColorID fields, relating them on that field and you pull the color field. Now open the query and the colors names will be there. In general, you don't store text in a table if you can normalize it into another table. Hope this helps,
Privateer
 
Thanks you very much for your replies!
It worked with the “[FONT=&quot]AND Not[Color]Is Null” statement. [/FONT]
 

Users who are viewing this thread

Back
Top Bottom