View Full Version : autonumber in form


sapowel
11-01-2001, 06:11 AM
i have a from that has a subform and the subform is a continuous form. I want to be able to number each item in my subform. I dont need to store the number it would be nice but it is not necessary. Any help would be appriciated. Thank you Scott

Ally
11-02-2001, 01:56 AM
Being a subform that you are adding to, I would presume that you have a separate table to feed it. If not, how are you doing it?

If you are using a separate table, you should be able to just add an autonumber to the table that is feeding the subform.

sapowel
11-02-2001, 06:24 AM
that would work but i am trying to start over a 1 on the next subform, all i need is for access to number every new entry in the subform and then when i open another form i want it to start over a 1 again.

Pat Hartman
11-02-2001, 02:09 PM
There is an example of how to do this in solutions.mdb.

Xenix
11-06-2001, 04:23 AM
Hello I had a very similar problem like this: maybe you can modify this code to work for you:

Private Sub Form_BeforeInsert(Cancel As Integer)
On Error GoTo Form_BeforeInsert_Err

' Set Line No to "Max" + 1
Forms![Quotation].Form![QuotationProducts]![Item] = DMax("[Item]", "Products", "[Quote]=" & Forms![Quotation]![quote]) + 1

If (IsNull(Forms![Quotation].Form![QuotationProducts]![Item])) Then

' If result was Null (this is the first line), set to 1
Forms![Quotation].Form![QuotationProducts]![Item] = 1

End If

Form_BeforeInsert_Exit:
Exit Sub

Form_BeforeInsert_Err:
MsgBox Error$
Resume Form_BeforeInsert_Exit

End Sub

I had a form that required the item number to reset on each new quote to a customer, this will keep adding 1 to item number until the the quote number changes then it will reset to 1, hope it helps you

Mike

[This message has been edited by Xenix (edited 11-06-2001).]