[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

UPDATE TOP in MS Access

Posted on 2011-03-10
4
Medium Priority
?
645 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
3 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
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.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

873 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