Autonumber problem

04-18-2004, 04:40 PM
i got an autonumber 2 textbox called "CustomerID", and "Customer Name" i got a button called "new"

The code for new button is:

Private Sub cmdAdd_Click()

Both textbox and button are linked with ADodc, now when i click on new button both textboxes clear.
The problem is that the textbox "CustomerId" is an autonumber i dont want it to clear i want it to show the next number.

For example:

Currently in CustomerId textbox the number is 10 i click on new button the customer name filed clear and customerid textbox becomes 11.
How would i solve this problem

04-19-2004, 07:48 AM
CAn some 1 pls help

04-19-2004, 07:58 AM
You can't, not really. Autonumbers don't exist in your database until after a record has been added & committed. You can make assumptions, if using a sequential autonumber vs random autonumber, that the next number will be the last active autonumber +1. But that is a bad assumption in my opinion. Regardless, I don't think you can do that anyway, since you have the autonumber textbox linked to your data control, you will probably get an error trying to supply your own value; or at best, it just gets replaced with the real value after the record addition has been committed.

04-19-2004, 08:04 AM
You should be doing nothing with your AutoNumber field regarding modifying its value. The only things you should be doing include: write a query to return the highest value, lowest value, do a search for records based on its value, etc.

An Autonumber field is just that, automatic. Let Access do the work for you. You never have to modify it or increment it. This is the point of autoNumber is created and indexed after your add a new value. You should never have to do anything with this field until after a new record is saved. And even then, it should only be used for a search mechanism.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum