title: Writing a Iif statement to update a table
body: <p>I am using Access 2010.</p>
  
  <p>I am trying to do an operation between three tables. The first and second table have an identical ID field, and so are joined using this. The second and third table have the IDs of departments, and so are joined using this. Not all of the IDs in the second table exist in the third table, though.</p>
  
  <p>I am trying to run a query that will update a field in the first table. The query will determine whether the Department ID in the second table exists in the third table. If it does, it uses another field in that third table (Department ID Full Name) to update the first table. If it doesn't, it uses the existing Department ID in the second table to update the first table.</p>
  
  <p>This is what I've got so far:</p>
  
  <pre><code>Field: Relevant field in Table 1
  Table: Table 1
  Update To: IIf([Table 2].[Dept ID] In (SELECT [Table 3].[Dept ID] FROM [Table 3]),[Table 3].[Dept ID Full Name],[Table 2].[Dept ID])
  </code></pre>
  
  <p>I've never written anything like this before and am totally new to Iif queries, so am not sure if this is even remotely close! Currently I have an error: "Operation must use an updateable query".</p>
  
  <p><strong>Edit - In SQL:</strong></p>
  
  <pre><code>UPDATE 
      ([Table 1] INNER JOIN 
          [Table 2 ON [Table 1].[ID] = [Table 2].[ID]) INNER JOIN 
              [Table 3] ON [Table 2].[Dept ID] = [Table 3].[Dept ID] 
  
  SET [Table 1].[Dept] = 
  
  IIf([Table 2].[Dept ID] In (SELECT [Table 3].[Dept ID] FROM [Table 3]),
  [Table 3].[Dept Name],[Table 2].[Dept ID]);
  </code></pre>