473,379 Members | 1,257 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,379 software developers and data experts.

How to get the next row id using access

1
I want to retreive the Next Value_ID from a table in MS Access Database, incremented automatically, and stopping after reaching the MAX VALUE_ID.
I can manage this with Oracle. Can any body tell me how to write the syntax for getting the NEXT VALUE_ID in MS Access and stopping when the MAX VALUE_ID is reached.
Feb 2 '10 #1
2 3281
Glenton
391 Expert 256MB
I know I had to do something similar some years back, and found it was very difficult. Eventually hired an access guru who coded a macro or something. I didn't look into the details, but I gather it was tricky.

Hopefully I'm wrong...
Feb 13 '10 #2
jota69
9
Assuming you have a database with at least one table, and some records.
Assuming also that the table contains a primary key or id field, and that key value increases automatically.
If you create a function that has id field records, and checks that this value is not greater than MaxValue.
If so, a message informs you of the event, otherwise, what you want to do, for example save the new record.

Assuming you have a process that validates data entered by the user before saving.
From this process, you can call the function, before validating the data is done.
If the function returns true (reached Maxvalue), warn the user through a message, and exit the process.
Otherwise, save your changes.

Expand|Select|Wrap|Line Numbers
  1. Function FindRecordCount(strSQL As String) As Long
  2. Dim IsMaxValue as Boolean = false
  3. Dim YourDatabase As DAO.Database
  4. Dim rstRecords As DAO.Recordset
  5.  
  6. On Error GoTo ErrorHandler
  7.  
  8. Set YourDatabase = CurrentDb
  9.  
  10. Set rstRecords = YourDatabase.OpenRecordset(strSQL) ' strSQL = Connection string.
  11.  
  12. If rstRecords.EOF Then
  13.       FindRecordCount = 0
  14. Else
  15.       rstRecords.MoveLast
  16. FindRecordCount = rstRecords.RecordCount
  17. End If
  18.  
  19. if FindRecordCount>=100 then    ' here determine Max value yourself.
  20. IsMaxValue =  true
  21. Else
  22. IsMaxValue =  false
  23. End If
  24.  
  25.    rstRecords.Close
  26.    YourDatabase.Close
  27.  
  28.    Set rstRecords = Nothing
  29.    Set YourDatabase = Nothing
  30.  
  31. Return IsMaxValue 
  32.  
  33. Exit Function
  34.  
  35. ErrorHandler:
  36.    MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
  37. End Function
hope this help.
Mar 18 '10 #3

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

Similar topics

7
by: simonwittber | last post by:
>>> gen = iterator() >>> gen.next <method-wrapper object at 0x009D1B70> >>> gen.next <method-wrapper object at 0x009D1BB0> >>> gen.next <method-wrapper object at 0x009D1B70> >>> gen.next...
4
by: Vincent Yang | last post by:
I'm using Access 2002. My database is in Access 2000 format. I'm designing a form to collect responses to a 40-item questionnaire. I can fit four list boxes on a screen, so I plan to have 11 tab...
4
by: hinrich | last post by:
Hello, I have a completely new system (windows xp prof.), office xp 2002 with sp 3. When I create a new and empty Accesss database, create an empty table and then create a new form using a...
1
by: chrissmith_76_Fed_Up_With_Spam | last post by:
Hello all, I am using Access 2002, with file format of Access 2000, and am experiencing a problem. I have a subform that is shown in datasheet view for users to edit data direct to a table. ...
13
by: Joseph Garvin | last post by:
When I first came to Python I did a lot of C style loops like this: for i in range(len(myarray)): print myarray Obviously the more pythonic way is: for i in my array: print i
27
by: Kim Webb | last post by:
I have a field on a form for project number. I basically want it to be the next available number (ie 06010 then 06011 etc). In the form I create a text box and under control source I put: =!=...
4
by: timasmith | last post by:
I guess more the fool me for attempting with MS Access but if I execute select max(nbr) from mytable nextnbr = maxnbr + 1 insert into mytable (nextnbr...) multiple times - it appears the...
4
by: Neo | last post by:
I found on error resume next doesn't work in for each... e.g. on error resume next for each x in y 'do stuff next if you have an error in for each loop, it falls in infinite loop... it...
11
by: scsTiger | last post by:
I am using Access 2000 as the front end and MS SQL 2000 as the backend. I have a one record form that I set using something like: strSQL = "SELECT * FROM dbo_WBACCT WHERE...
3
JodiPhillips
by: JodiPhillips | last post by:
Hello All, I'm trying to limit the number of attempts a user has to log into an MS Access 2003 database, but am having very little success. My current code for log in is as follows (and thanks...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.