0

I'm working on a project using jsp and Microsoft Access.

There are three tables in which a same field is used as Receipt_No.
This can get from Recp table, which has a only one field: Receipt_No (AutoNumber, Primary Key).

Now my question is, how can I insert in this AutoNumber field with every generation of receipt?.

Shin
  • 664
  • 2
  • 13
  • 30
samiksha
  • 73
  • 1
  • 3
  • 7
  • 1
    It is generated automatic, thats why its called AUTOnumber. – Jacob Aug 24 '11 at 07:46
  • possible duplicate of [How to create Auto Number Field in access?](http://stackoverflow.com/questions/1072932/how-to-create-auto-number-field-in-access) – KV Prajapati Aug 24 '11 at 07:48

2 Answers2

2

WARNING This is ghetto. (But then again I'm thinking a table with ONLY an autonumber field is kinda ghetto too, so oh well.)

INSERT INTO yourTable (your_autonumber_field) SELECT max(your_autonumber_field) + 1 FROM yourTable

Not elegant, but it works. That will create a new record in your Receipt table. It defeats the whole purpose of having an autonumber field but I don't see another way to use SQL to create a record in a table with only an autonumber field. You can then retrieve the newly created receipt ID with a SELECT max(your_autonumber_field) FROM yourTable for use in your FK fields in the other tables.

Banjoe
  • 1,768
  • 12
  • 13
  • 1
    Just accept this answer - mark it as the accepted answer by clicking on the check box outline to the left of the answer – Igor Turman Aug 24 '11 at 15:22
1

The autonumber field has the property that it gets numbered accordingly as the records are entered into the table. its smthng like autoincrement

user909058
  • 188
  • 1
  • 2
  • 11