Microsoft Access - Updating Null fields with visible values

Asked By Charles Bostic on 19-Jun-12 01:30 PM

I have some query experience but I'm having trouble converting this particular query over to Access VBA Docmd.Runsql. I'm trying to fill all blank records within each group ID by extracting visible values of the same column. Below is a sample of what I'm trying to achieve with the Phone column:

Group_ID First Last Phone Group_ID First Last Phone
1 Charles Bostic 555-1212 1 Charles Bostic 555-1212
1 Charles Bostic   1 Charles Bostic 555-1212
1 Charles Bostic   1 Charles Bostic 555-1212
2 james Kirkland 732-2233 2 james Kirkland 732-2233
2 james Kirkland   2 james Kirkland 732-2233
2 james Kirkland   2 james Kirkland 732-2233
3 Jane Moe   3 Jane Moe 221-2020
3 Jane Moe 221-2020 3 Jane Moe 221-2020
3 Jane Moe   3 Jane Moe 221-2020
4 Jackie Smith   4 Jackie Smith 215-0987
4 Jackie Smith   4 Jackie Smith 215-0987
4 Jackie Smith 215-0987 4 Jackie Smith 215-0987

Thanks,

Charles

wally eye replied to Charles Bostic on 19-Jun-12 05:19 PM
Can you post your current SQL, maybe table structures?
Charles Bostic replied to wally eye on 19-Jun-12 10:02 PM
The SQL code I currently designed looks like this:

DoCmd.RunSQL "UPDATE test INNER JOIN test2 ON (test.group = test2.group) SET test2.phone = test.phone WHERE test2.phone Is Null 
wally eye replied to Charles Bostic on 20-Jun-12 11:48 AM
I don't think the issue is with your update query, but with your reporting query.  Can you post the query you are using for your sample, along with table structure?
Charles Bostic replied to wally eye on 20-Jun-12 01:51 PM
This DLookup code updates the results I'm looking for in an Access query:

Phone_Update: IIf(IsNull([test]),DLookUp("Phone ","Test"," Group='" & [Group] & "' AND phone "),"")

wally eye replied to Charles Bostic on 20-Jun-12 05:24 PM
OK, now I'm even more confused. Why do you have a table with the same entries replicated four times?  Wouldn't it be better to have a table with the correct entries, then join it to a transaction table when needed?

You could use a query that links the table back to itself, checking for nulls and not nulls:

UPDATE Table1 INNER JOIN Table1 AS Table1_1 ON Table1.Group = Table1_1.Group SET Table1_1.Phone = [table1]![Phone]
WHERE (((Table1_1.Phone) Is Null) AND (Not (Table1.Phone) Is Null));
Charles Bostic replied to wally eye on 25-Jun-12 09:40 PM
I apologize for the confusion above. The code you wrote extracts the value I'm looking for but only when the values are in the first row of the group. Since the values can display in random order of the group, I need a dlookup type function that will search the whole group and paste the value where the record is blank.   Thanks
wally eye replied to Charles Bostic on 26-Jun-12 10:20 PM
The query I posted will update the null phone numbers with a non-null number from a matching group ID, not necessarily the first record in the table or the first record for a specific group.

Try pasting the SQL into the SQL view of a query and see if it works.
Charles Bostic replied to wally eye on 28-Jun-12 09:03 AM
Wally Eye, I thank you very much for your awesome help and your patience. It works like a charm. 
wally eye replied to Charles Bostic on 28-Jun-12 10:51 AM
You're most welcome, glad to be of assistance.