Hello, Can someone please tell me how to display an autonumber in a text box. I am using the ado control to connect to my database.

I am doing a small project for college in which i have to create a customer record and blah blah etc.

When i press the add new customer button i'd like it to display the new customer number. If i can't do this i'd like it to display (Autonumber) like Access does.

Any help would be appreciated.

I've only been programming visual basic for about a month.

I've done some C++ and Progress 4GL programming as well so i'm not a complete novice but i'm not brilliant at it.

I've included my source in a zip file if your interested.

Thanks.

I'm not 100% sure what you are doing, or what you want (I guess I don't understand autonumber) if you want me to write a function in VB for you, to generate a random number between such and such, that's no sweat. If it's something more complex, that's no problem either... but I need to understand the concept first.

I thought i was pretty clear, i'll try again. I have created a database.

The database creates a customer record.

When i press the add new button. I would like the program to display the next new customer number in the customer number text box.

I dont need to create a random number because i have set the database to use the autonumber setting in microsoft access. It just increments by 1 each time i add a new record.

The problem is that when i press add new, it just completely clears the form.

From what you describe its not so easy unless you generate the number yourself instead of using an autonumber field in access. The trouble is that Access generates the next number AFTER you add the record so you have no certain way of knowing what the next number will be. Sure you could take a guess and add one to the last number, but what happens if you deleted the last number? You see my reasoning here? The only real way of doing it is to do the numbering yourself in another table.

So, you would increment the counter in the other table when you add a record, but you would not decrement it when you delete one. Then in the customer table you would have an id field that is just a regular long, and fill this with the value out of the counter table when you add a new record.

ok, thanks for your help. I am just going to leave it. Is there any way to just display the text "Autonumber" in the text box without causing validation errors as its set as a long in the database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.