Vba – Check/update a row of values based on a single column header


I have database with many tables. In the first table, I have a field called status.

table 1
idno   name    status
111    hjghf   yes
225    hjgjj   no
345    hgj     yes

Other tables could have same idno with different fields.

I want to check the status for each id no and if it is yes then for that id number in all tables for all null and blank fields I want to update them as 111111.

I am looking for a sample vba code for this which I can adapt.


Best Solution

Here is some largely untested code. Hopefully it will give you a start.

Sub UpdateNulls()
Dim strSQL As String
Dim rs As DAO.Recordset
For Each tdf In CurrentDb.TableDefs
    If Left(tdf.Name, 4) <> "Msys" And tdf.Name <> "Table1" Then
        strSQL = "Select * From [" & tdf.Name & "] a Inner Join " _
        & "Table1 On a.idno = Table1.idno Where Table1.Status = 'Yes'"

        Set rs = CurrentDb.OpenRecordset(strSQL)

        Do While Not rs.EOF
            For i = 0 To rs.Fields.Count - 1
                If IsNull(rs.Fields(i)) Then
                    rs.Fields(i) = 111111
                End If

    End If
End Sub
Related Question