Update Query Help

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
778
Office Version
  1. 2016
Platform
  1. Windows
I’m new to Access and in the process of creating a database that is populated via Excel. I’ve created a linked Excel table and Access table. Then created an Append Query to do the updating. The Query updates the table in blocks of 50 records daily. This works perfectly.

I now need to create an Update Query. Creating the Query is straight forward enough. But on a daily basis I receive information that needs to be amended. My problem is updating one figure without wiping the whole record.

I know I need to write the formula in the field part. In Excel, the formula would be: =IF(A1<>"",1,2)

Any pointers would be much appreciated.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi, Thanks for the reply.

I can do the update, thanks to both pages. But the pages don't say if I only wanted to replace one value how to do it.

I was think along the lines of an update query with a Criteria in each field that says if Field1 Table1 is empty then leave the value in Field1 Table2. But if Field1 in Table1 has a value then overwrite Filed1 Table2.

I hope that makes sense.
 
Upvote 0
How are table1 and table2 linked?

If you have the query that joins these two tables, can you post it (change your query to SQL view, and cut and paste the code here)?
 
Upvote 0
See if this helps.

Assuming you have joined the two tables in the query, select to display only Field1 from Table1 and Table2.

Now, since you only want to select records where Field1 from Table1 is not blank, then enter criteria on the Criteria line under the Table1 Field1 field, something like:
Not Is Null
or
<>""

Now, change the query type to an Update Query, and enter the following on the Update To line under Table2 Field1:
[Table1]![Field1]

Now, if you run the Update Query, it should only update Table2 Field1 for matching records where Table1 Field1 is not empty.
 
Upvote 0
Hi,

I am using some test tables to get things working before attempting it on my main tables.
The SQL is:

UPDATE Table1 INNER JOIN Table2 ON (Table1.ID = Table2.ID) AND (Table1.Date = Table2.Date) SET Table1.[Date] = [Table2]![Date], Table1.Amount = [Table2]![Amount], Table1.Colour = [Table2]![Colour]
WHERE ((Not (Table1.Amount) Is Null) AND (Not (Table1.Colour) Is Null));

Table1 is ID = Autonumber, Date, Amount, Colour. Table2 is exactly the same layout. I have linked the ID and the date fields.

I tried Not is Null, which I was expecting to work. But it over wrote the number in Table1.

Am I missing the obvious
 
Upvote 0
I think you have it backwards. I thought you said you wanted to overwrite the values in Table2 Field1, but your code does just the opposite.

The snippet of code you posted below updates Table1, not Table2.
Code:
SET 
   Table1.[Date] = [Table2]![Date], 
   Table1.Amount = [Table2]![Amount], 
   Table1.Colour = [Table2]![Colour]
If you want to update Table2, you need to reverse them
Code:
SET 
   Table2.[Date] = [Table1]![Date], 
   Table2.Amount = [Table1]![Amount], 
   Table2.Colour = [Table1]![Colour]
 
Upvote 0
Hi,

Your right. I was rushing to get home and wasn't paying attention. The update works fine. But it still overwrites the whole record. I've tried Criteira: Not Is Null <>"" Is Null.

I think I'm missing the obvious but can't see what.
 
Upvote 0
What do you mind that it is updating the whole record? It should only be updating the fields in the SET clause of your SQL code.

Or do you mean it is updating your whole record set, meaning it is updating records (not fields), that it should not be? If so, try this criteria (NULLs and blanks are NOT treated the same in Access, this should catch both).

Not Is Null and <>""
 
Upvote 0
Hi,

If I had a table with 10 record and ten fileds. It would mean that I have 100 bits of information. What I can't work out is, if I wanted to replace 1 bit or many bits of information in one record using an Update query. How can I do without having to replce the whole record. I've tried every combination of Null and am now starting to think that using IIf is how to do it.

I've been trying to solve this for a few days now and am no further forward. Other than the help you have offered and doing lots and lots of web searching.

The search goes on.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top