Avatar of Jay Williams
Jay Williams
 asked on

How do I deal with null values in Access update queries?

I have imported ranges from Excel sheets that I need to use to update records in an Access table. The sheets go into a table identical to the one containing the records to be updated, including the key index ID (numbered, not autonumbered).  The recordset that is used to update has many null values in the records, sometimes all of the matching records may have ALL null values in every field. Here's my query sql:
UPDATE WorkingListT INNER JOIN PickListT ON WorkingListT.PID = PickListT.PID SET PickListT.Sloc = [WorkingListQ].[Sloc], PickListT.Priority = [WorkingListQ].[Priority], PickListT.DaysPastPickDate = [WorkingListQ].[DaysPastPickDate], PickListT.Pcs = [WorkingListQ].[Pcs], PickListT.Links = [WorkingListQ].[Links], PickListT.Reservation = [WorkingListQ].[Reservation], PickListT.ResOnly = [WorkingListQ].[ResOnly], PickListT.ClosedOnDate = [WorkingListQ].[ClosedOnDate], PickListT.WBS = [WorkingListQ].[WBS], PickListT.HXSlocInv = [WorkingListQ].[HXSlocInv], PickListT.SlocLineLocation1 = [WorkingListQ].[SlocLineLocation1], PickListT.SlocLineLocation2 = [WorkingListQ].[SlocLineLocation2], PickListT.SlocLineLocation3 = [WorkingListQ].[SlocLineLocation3], PickListT.LeadTimeDays = [WorkingListQ].[LeadTimeDays], PickListT.ResReassgnd = [WorkingListQ].[ResReassgnd], PickListT.Countdown = [WorkingListQ].[Countdown];

Open in new window

Pretty straightforward, but when I run it, I get a parameter error for every field.  I tried using the IIf statement in the criteria, but I can't seem to get the syntax right.  Any better ways around this? Any ideas?
Microsoft Access

Avatar of undefined
Last Comment
Jay Williams

8/22/2022 - Mon
Scott McDaniel (EE MVE )

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dale Fye

Scott's comment "determine what you want to do with them" is critical.

If the destination table already has a value in that field, do you want to overwrite it with a NULL (in your source table), or do you want to keep the previous value if no new value is provided?  If you want to keep the previous value you could probably use syntax similar to:

NZ([WorkingListQ].Priority, PickListT.Priority)
Hamed Nasr

Agree with Scott's comment.

I add use Nz([WorkingListQ].[Sloc]) to allow for different data types of corresponding field.

Use the same idea with other null expected fields.
Jay Williams

Plenty there to chew on, guys.  Let me scratch my noggin.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Jay Williams

Yeah, there's something fundamental I'm not getting.  Tried all of your syntax, read the method support page; quotes, no quotes, same error. I think I get it conceptually, but still missing something.  Argh.
Jay Williams

Got it, men.  It's always something easy and stupid isn't it?  I fat-fingered the name of the table.  You were all right, and taught me a lesson (again) thank you.
Jay Williams

These guys aren't just smart, they're generous and kind.
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.