Updating Table (1 Viewer)

kirkm

Registered User.
Local time
Tomorrow, 01:11
Joined
Oct 30, 2008
Messages
1,257
I've run a delete query on my table and now want to update its count Field (to number 1 to recordcount).
Can an update query do this? I'm a bit stumped how to construct the sql.

Or should I just iterate through a recordset and edit each record ?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:11
Joined
May 21, 2018
Messages
8,527
You can do an update based on a ranking query.
Or it is just as easy to loop a recordset.
 

kirkm

Registered User.
Local time
Tomorrow, 01:11
Joined
Oct 30, 2008
Messages
1,257
Thanks Maj. After reading the link the latter method seems way easier !
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:11
Joined
May 21, 2018
Messages
8,527
Here is a real simple one. I just did the rank query. But the problem is that query is not updateable, so you are back to doing it with a recordset anyways.
 

Attachments

  • RankDemo.accdb
    1.8 MB · Views: 96

kirkm

Registered User.
Local time
Tomorrow, 01:11
Joined
Oct 30, 2008
Messages
1,257
Thanks. A lot easier to follow like that.
 

apr pillai

AWF VIP
Local time
Today, 18:41
Joined
Jan 20, 2005
Messages
735
With three Queries The Customers Table can be updated with the Rank Values, taking your qryRank Query as Source (taking MajP's attachment as an example), rather than manually updating each record.

SELECT Query1 SQL: SELECT Customers.*, qryRank.CustomerRank AS Rank
FROM Customers INNER JOIN qryRank ON Customers.CustomerID = qryRank.CustomerID;

Make Table Query2 SQL: SELECT Query1.* INTO CustomersOut FROM Query1;

Update Query3 SQL: UPDATE CustomersOut SET CustomersOut.CustomerRank = [CustomersOut].[Rank];
 

Users who are viewing this thread

Top Bottom