Solved

UPDATE TOP in MS Access

Posted on 2011-03-10
4
520 Views
Last Modified: 2012-05-11
I'm getting: "Syntax error in UPDATE statement" in Access 2007 for the following:

DoCmd.RunSQL "UPDATE TOP(1) [Team 01] SET FirstName = 'Carl', LastName = 'Crawford', Rank = 3, Pos1 = 'OF', Pos2 = '', Pos3 = '' WHERE Position = 'OF'"

The following works but updates too many records:

DoCmd.RunSQL "UPDATE [Team 01] SET FirstName = 'Carl', LastName = 'Crawford', Rank = 3, Pos1 = 'OF', Pos2 = '', Pos3 = '' WHERE Position = 'OF'"

[Team 01] has multiple (3) records where Position = 'OF'.  The second statement above updates all 3 records.   I only want to updated one of those records when Carl Crawford is selected.
0
Comment
Question by:CMCONE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35102187
If you only want to update the carl crawford record why are you not including that in the where clause:
DoCmd.RunSQL "UPDATE [Team 01] SET FirstName = 'Carl', LastName = 'Crawford', Rank = 3, Pos1 = 'OF', Pos2 = '', Pos3 = '' WHERE FirstName = 'Carl' AND LastName = 'Crawford' AND Position = 'OF'"

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 35105516
>>Zone: MS SQL Server<<
If you are using MS Access than you had best post in that zone.  MS Access uses a different SQL dialect.
0
 
LVL 1

Accepted Solution

by:
infochip earned 500 total points
ID: 35111442

I believe on sql server Transact Sql allows the TOP command in non-select statements.  standard sql does not.  You have to do something like this


SQL = "delete T1 from "
SQL = SQL & " (Select top " & NumberToDelete & " * from qryParserEmaildateAscending where " & sqlCondition & ") T1"
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

691 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