473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Increment a column when column value changes

I am new to vba access and I am trying to create a field that will increment when the another field value changes. Any assistance will be welcomed. This is what I have so far.
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim n As Integer
  3. Dim db As Database
  4. Dim rs As Recordset
  5. Dim rsOne As String, rsTwo As String
  6.  
  7.  
  8. Set db = CurrentDb
  9. Set rs = db.OpenRecordset("qrySortData", dbOpenDynaset)
  10.  
  11.  
  12. rs.MoveFirst
  13.  
  14. n = 1
  15. Do While (Not rs.EOF)
  16.  
  17.     rsOne = rs.Fields("Folder")
  18.     rs.MoveNext
  19.     rsTwo = rs.Fields("Folder")
  20.     If rsOne = rsTwo Then
  21.  
  22.  
  23.         rs.Edit
  24.         rs.Fields!Counter = n
  25.         rs.Update
  26.         rs.MoveNext
  27.         rs.Edit
  28.         rs.Fields!Counter = n
  29.         rs.Edit
  30.  
  31.         rs.Update
  32.         rs.MoveNext
  33.     Else
  34.  
  35.         i = n + 1
  36.         rs.Edit
  37.         rs.Fields!Counter = i
  38.         rs.Update
  39.         rs.MoveNext
  40.         rs.Edit
  41.         rs.Fields!Counter = i
  42.         rs.Update
  43.         rs.MoveNext
  44.  
  45.  
  46.  
  47.     End If
  48. Loop
  49.  
  50.  
  51.  
  52. rs.Close
  53. Set rs = Nothing
  54. db.Close
  55. End Sub
Apr 6 '17 #1
0 833

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: codecraig | last post by:
Hi, I am using Tkinter and I have a Label and a Scale. I want to update my label everytime the Scale value changes. What is the best way of doing this? Do i have to bind for every event type? ...
5
by: pelcovits | last post by:
How do I get Access to put a blank in a report column (but not eliminate the record completely), when the field in question is currency format, and the value is zero? My understanding is that null...
2
by: Mike Gage | last post by:
I am trying to populate DataSets with results from SQL queries. Usually, to that end, the DataSet.Fill method works fine. If however the table includes a character field populated with a space,...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
4
by: Rodger Dusatko | last post by:
In VB .NET I am having problems setting breaks. I want the break to be independant of any single function: for example: err.number or global variables When I try to set a break with the 'Data'...
5
by: Stuart | last post by:
Hi all, Iv'e got a page that has a mass amount of input fields, all of which require a decimal figure. To make it easier when it comes to inputting data, I'm trying to setup + and - links that...
7
by: Macolm64 | last post by:
I am looking for some code that would loop until two cell values in excel equal the same. By cell value I mean the result of the formulas in the cells are the same. This procedure needs to be run...
3
by: crjunk | last post by:
Hi Everyone, I have a web form that I would like to enhance. What I'd like to do is this: A user adds/edits the text in a textbox. I want the adjoining label to change color. Example: User...
2
by: Dresse | last post by:
Hello I was wondering if it is possible to define a save location when a value in a combobox is selected. ex. Combobox: a b c
13
by: philqw78 | last post by:
I have a spreadsheet (Excel 2003*) Column C changes to "Y" when all the necessary data has been input in that row. I want a message box to appear when the value in column C changes to Y for the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.