Solved

MS ACCESS update query with multiple criteria

Posted on 2009-04-09
9
1,264 Views
Last Modified: 2012-05-06
This "allmost" works:
Ocassionally incorrect data will be uploaded (_, am, pm).
Most of the time correctly formated data will be uploaded.

Update To:
IIf([P_JOBTIME]="_","3:00 AM",
IIf([P_JOBTIME]=" am","3:00 AM",
IIf([P_JOBTIME]=" pm","3:00 AM",)))

This finds the criteria and updates it correctly BUT it deletes any record not meeting the criteria.
Meaning ligitimate data that does not need be touched is deleted.
How do I maintain the legitimate data?

Thanks for the help,
Ralph
0
Comment
Question by:RalphHxyz
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 20

Expert Comment

by:clarkscott
ID: 24108324
I think if you delete the last comma (the last nested ELSE) it might work???
IIf([P_JOBTIME]=" pm","3:00 AM",)))
---------------------------------------|--------------
Scott C
0
 
LVL 77

Expert Comment

by:peter57r
ID: 24108338
Sorry- but you are looking at something incorrectly somewhere.

There is no possibility of Access deleting any records in an update query.
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 24108463
I assumed the Ralph meant that the data was being 'blanked out' - not entire record deleted.

Is my assumption correct?
S
0
 

Author Comment

by:RalphHxyz
ID: 24108478
"There is no possibility of Access deleting any records in an update query"
If so why am I asking the question?
That's about the stupidest "Expert" reply I have ever seen.
Ralph
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 24108548

update tableX
set [P_JOBTIME]=IIf([P_JOBTIME]="_","3:00 AM",
IIf([P_JOBTIME]=" am","3:00 AM",
IIf([P_JOBTIME]=" pm","3:00 AM",[P_JOBTIME])))
0
 

Author Comment

by:RalphHxyz
ID: 24108780
Is blanked out different from deleted?
I have closed and reopened the table but the "good" records are not there!
Some thing about my Update Query that I have found out so far.
IIF() is supposedly limited to two criteria.  That should be noted.
For more than two criteria one should use a SWITCH() function.
SWITCH([P_JOBTIME]="_","3:00 AM",[P_JOBTIME]=" am","3:00 AM",[P_JOBTIME]=" pm","3:00 AM")
 But I am still deleting good data (with a relly puzzelling modification see the pictures attached the 5:30 am record remained all of the other records have been deleted except those that met the criteria)
I have been using ACCESS for 15 years and I agree a UPDATE query does not "normally" delete records.
Ralph

1-Table-Start.png
2-Query.png
3-Prompt.png
4-Results.png
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 24108893
RalphHxyz,

try my post at http:#a24108548
0
 

Author Comment

by:RalphHxyz
ID: 24108922
Adding [P_JOBTIME]) deletes all of the records even those that meet the criteria.
UPDATE qryDetail_Crosstab
SET qryDetail_Crosstab.P_JOBTIME = Switch([P_JOBTIME]="_","3:00 AM",
[P_JOBTIME]=" am","3:00 AM",
[P_JOBTIME]=" pm","3:00 AM",[P_JOBTIME]);
Ralph

5-Prompt2.png
6-Results.gif
0
 

Author Comment

by:RalphHxyz
ID: 24109091
capricorn, you da man!!
UPDATE qryDetail_Crosstab
SET qryDetail_Crosstab.P_JOBTIME = IIf([P_JOBTIME]="_","3:00 AM",
IIf([P_JOBTIME]=" am","3:00 AM",
IIf([P_JOBTIME]=" pm","3:00 AM",[P_JOBTIME])));
Works!!
Thanks so much,
RAlph
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now