Solved

UPDATE TOP in MS Access

Posted on 2011-03-10
4
492 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

697 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