473,666 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there any way I can define a starting value for an Auto-Increment Field in a table

54 New Member
Hi

I have a table that has as its Primary Key the Auto-Increment Field:
Equipment_Numbe r.
In M.S. Access is there any way to define a starting number for the field?

OR another way in which I could save the same problem would be:

I have a form frmAddNew_Equip ment, once all the fields are filled in correctly and it has been verified that there is no double entry etc, and the 'SAVE' button is clicked (unbound form), another form, bound to a query pops up with the new equipment number. The person using the database then grabs a physical Label and attaches that to the new piece of equipment. However the labels start at number 1000. Is there anyway I can modify the query I use in the pop up form, so that 1000 will be added to the number the query produces, before the new number is displayed in a text box on the pop up form.

This is the query that drives the New Equipment_Numbe r textbox field on the pop up form:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblEquipment.Equipment_Number
  2. FROM tblEquipment
  3. WHERE (((tblEquipment.Serial_ID)=(Forms!frmAdd_Equipment!txtSerial_Number)));
Again thank you for any help

Mike
Nov 17 '08 #1
11 4068
PianoMan64
374 Recognized Expert Contributor
Hi

I have a table that has as its Primary Key the Auto-Increment Field:
Equipment_Numbe r.
In M.S. Access is there any way to define a starting number for the field?

OR another way in which I could save the same problem would be:

I have a form frmAddNew_Equip ment, once all the fields are filled in correctly and it has been verified that there is no double entry etc, and the 'SAVE' button is clicked (unbound form), another form, bound to a query pops up with the new equipment number. The person using the database then grabs a physical Label and attaches that to the new piece of equipment. However the labels start at number 1000. Is there anyway I can modify the query I use in the pop up form, so that 1000 will be added to the number the query produces, before the new number is displayed in a text box on the pop up form.

This is the query that drives the New Equipment_Numbe r textbox field on the pop up form:

SELECT tblEquipment.Eq uipment_Number
FROM tblEquipment
WHERE (((tblEquipment .Serial_ID)=(Fo rms!frmAdd_Equi pment!txtSerial _Number)));

Again thank you for any help

Mike

Hey Mike,

This is one of those reasons that all new users of MS Access database fall into. You're not able to change the ID number of Autonumber field to a fixed number without manipulating the database a little. If you're database has a count of 10 and you want to go to 999, then you would add the appropriate number of records to the database (989), so the next number that is issued would be 1000. There is no feature to adjust this number at all if, for some reason that the numbers get out of sequence. this is why this is not always a good idea to use the Autonumber Primary Key field as a product code, because it is not changable.

As long as you're ok with my solution, that should allow you to change the number, but other than that, there isn't any other way to change the number a Autonumber field in a MS Access Database.

Now to change it back, you would have to clear the entry table, perform a compact on the database, and that will reset the number back to 1. Those are your only options for manipulating the autonumber field.


Hope that helps,

Joe P.
Nov 17 '08 #2
NeoPa
32,568 Recognized Expert Moderator MVP
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.

Administrator.
Nov 17 '08 #3
NeoPa
32,568 Recognized Expert Moderator MVP
The short answer to your question (I try to be uncomplicated but it doesn't come naturally to me) is that the AutoNumber type, though it looks as if it may be the appropriate choice in such a situation, is not.

The standard approach is to find an alternative method of determining what a new index value should be. That way you have an almost unlimited flexibility to which values are used.
Nov 17 '08 #4
DonRayner
489 Recognized Expert Contributor
You can use an append query to append a record that is one less than the number you want to start numbering at.
Nov 17 '08 #5
NeoPa
32,568 Recognized Expert Moderator MVP
I'm sorry Ron, but that can only work if you append records UNTIL that point is reached. It will not allow you to specify a value for an AutoNumber field. See Joe's post above.
Nov 17 '08 #6
DonRayner
489 Recognized Expert Contributor
I'm sorry Ron, but that can only work if you append records UNTIL that point is reached. It will not allow you to specify a value for an AutoNumber field. See Joe's post above.
I do remember using that method before I learned the error of my ways with autonumbering. I just went and check to see if it works and it does.

I copied the origional table to a new table and deleted all the records in it. I then changed the autonumber field in the copy to a number field and placed one record with a number of 999 in it.

I created an append query to append the record from the new table into the origional tabel and then ran the query. It append the record with 999 as a number and then started numbering the table from 1000 after that.
Nov 17 '08 #7
ZaphodBBB
54 New Member
Hi everyone

Been away the last couple of days so have not seen all the replies.

(Hi NeoPa I'll have a look at the posting rules..as I say I have not really been on here since it was the scripts website 2 years ago, but I'll see how you like code displayed and do it in future)

Though by far probably not the most elegant(?) way out, what I ended up doing (on a Sat morning after a reasonably hard night) was to rename the Equipment_Numbe r field to Equipment_Numbe r_Real. Then I added another column(Field) called Equipment_Numbe r. I wrote a bit of code so that when an operator adds a piece of equipment to the database, and clicks the save record button, the code looks to the present Equipment_Numbe r_Real value, adds 1000 to it, then displays a little pop-up form with the new equipment number that has been allocated to the new piece of equipment, then saves that new number back to the table as the Equipment_Numbe r.

The only reason I asked the question, was that someone told me that you can start AutoNumber fields from a given value in the Alpha 5 database software and I wondered if Access would be the same.

Thanks for the responses
Mike
Nov 19 '08 #8
missinglinq
3,532 Recognized Expert Specialist
If I followed this correctly, you're now adding 1000 to your AutoNumber field to get your number for your label. If that's so, you've still got a problem! Autonumbers are intended to be used for one purpose and only one purpose, to provide a unique identifier for each record. Here's a post I've archived from a gentleman named John Vinson, MVP, explaining how autonumbers work:

When using Autonumber, do be aware that there will be gaps in the numbering - any record that's deleted will leave a gap; hitting <Esc> after starting a record will leave a gap; adding records using an Append query may leave a gap, often a huge one; replicating the database will make your invoice numbers random.

In short... it's best NOT to use Autonumbers for human consumption, and particularly not for consumption by accountants and auditors. Invoice sequences like 319, 321, 322, 385, 386, 221841246, -1083225152 make such people get very nervous.
As NeoPa said earlier, for the kind of field you're using, you need to use an auto-incrementing number hack such as one of these.

The first code here would be for an IDNumber that is defined in the table as Text:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If Me.NewRecord Then
  3.   If RecordsetClone.RecordCount = 0 Then
  4.    Me.IDNumber = "1000"
  5.   Else
  6.    Me.IDNumber = DMax("val([IDNumber])", "YourTableName") + 1
  7.   End If
  8. End If
  9. End Sub
If your "number" is defined as a Numerical field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If Me.NewRecord Then
  3.   If RecordsetClone.RecordCount = 0 Then
  4.    Me.IDNumber = 1000
  5.   Else
  6.    Me.IDNumber = DMax("[IDNum]", "YourTableName") + 1
  7.   End If
  8. End If
  9. End Sub
As John explained, AutoNumbers can leave gaps, so basing an equipment number on an AutoNumber can leave gaps. In certain circumstances, they can become random, so your equipment number can become random, with a number generated a month from now coming before a number generated next week.

Linq ;0)>
Nov 19 '08 #9
NeoPa
32,568 Recognized Expert Moderator MVP
(Hi NeoPa I'll have a look at the posting rules..as I say I have not really been on here since it was the scripts website 2 years ago, but I'll see how you like code displayed and do it in future)
Hi Mike.

I thought I hadn't seen you around for a while, and that would explain the rustines ;) In truth it's a standard response I use whenever I find a member not using the tags.

@Don
Fair point (about the AutoNumber start position).
I can't say that I've tried that specific sequence of events, but I do know that other attempts to add values to an AutoNumber field have failed for me (probably using a form I guess).
Nov 20 '08 #10

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

Similar topics

5
8854
by: Jonathan Brady | last post by:
I couldn't find this anywhere so I'm not sure that it exists. In most programming languages, one can define a value and then uses that value by referencing the name in all of the source, and if that value needs to be changed, then it's a simple matter of changing the definition, and the change will be reflected of course throughout the whole thing. Example:
2
4513
by: psundara | last post by:
Hi, I'm facing a peculiar problem of finding a way to interpret header information in a smart way. I have this header file that is shared by many users, which contains, among things, a few #define statements that associate GUIDs wih a friendly name. For e.g. consider the file zoo.h: ....
10
3444
by: Lars Netzel | last post by:
Hi! Is it possible to start a dial-up connection that is already created on the computer thru VB.NET, and then after it has dialed up get an idication of that there's a connection ( I guess ping some server?) and then send a mail and close the conenction? I really need some pointers in where to start to look for this! best regards
5
3263
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if I change 'auto' to 0 for left and right margin values; I have to leave those at 'auto'.. so I would like to know what exactly means 'auto' -- what value it represents exactly (and does it apply for all elements/values you might apply 'auto' to?)
6
2660
by: Andrew Poulos | last post by:
I'm using Windows Media Audio, via a WAX file, and I have some custom controls to start and stop the audio. While it works in IE, FF gives an error. The HTML looks like this: <object id='obj' type='audio/x-ms-wax' style='position:absolute; left:0px; top:0px;' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codeBase='http://activex... blah width='100' height='100'> <param name='FileName' value='wma_sample.wax'>
3
4871
by: placid | last post by:
Hi all, Using Tim Golden's wmi module you can get the service names import wmi c = wmi.WMI () stopped_services = c.Win32_Service (StartMode="Auto", State="Stopped") if stopped_services: for s in stopped_services: print s.Caption, "service is not running"
7
2417
by: miaohua1982 | last post by:
the code is as follows: #include<stdio.h> int arr={1,2,3,4,5,6,7}; #define size (sizeof(arr)/sizeof(arr)) int main() { int index = -1; int x = 0; int t;
1
1994
by: JavaXMLDev | last post by:
Hi I'm new to XML schema work, but wondered how, if at all possible, can you specify a relationship between the values of an element's attributes. Essentially I want context sensitive auto-complete for the attribute values of an element when creating an XML document. I dont know how to define the relationship ! Scenario: When using a location element and selecting the school value for the type attribute I would like to restrict...
9
23256
by: GloStix | last post by:
From some reason the entire webpage start about 5px from the top. I've margin:0 auto; the whole thing plus margin-top:0px; the whole thing too... #container { width: 700px; font-family: serif; font-size:14px; color: #222222; margin:0 auto; border-left:solid 1px #333333;
7
4697
by: PaulaCM | last post by:
Hello Again Byters (hmmm... that sounded better in my head!)! Question on Primary Keys / Auto numbering. I want to make sure that each record has its own individual ID (hence primary key) but, I just want to choose the starting point. So, instead of starting with record ID 1, I'd like to start with record ID 1024. (I'm replacing a paper system with an electronic one, but would like to keep going from where I left off). So, ideally I...
0
8787
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8561
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6203
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.