Sale Id , Number Increment Problem

  • Thread starter Malik via AccessMonster.com
  • Start date
M

Malik via AccessMonster.com

Hi,
I Have a Sale Invoice Form, which has a SaleID TextBox, This Field
automatically generate the next number on a new sale Invoic. I m using the
following script for this fiels :

in Form Load Event
Me!SaleID = NZ(DMax("[SaleID]", "[tablename]")) + 1

I Have "Save' And "Cancel" Command buttons on the form.


Now I have a problem that If I fill all required feilds in the form and I do
not save the record but Cancel or clear the current record on the the form,
Next Time it gives me a new Sale Id number.

For Example :
i m entring Data:

Sale Id : 56
Customer Name: Abc
Sales Details: XYZ


Now I Cancel It, Dont save the record, Close the form,

But Now when I will open the form The SaleId Will Put the No 57 in the field
while I have not saved any data on Sale Id no 56.

please tell me that how to control It.
 
M

Marshall Barton

Malik said:
I Have a Sale Invoice Form, which has a SaleID TextBox, This Field
automatically generate the next number on a new sale Invoic. I m using the
following script for this fiels :

in Form Load Event
Me!SaleID = NZ(DMax("[SaleID]", "[tablename]")) + 1

I Have "Save' And "Cancel" Command buttons on the form.


Now I have a problem that If I fill all required feilds in the form and I do
not save the record but Cancel or clear the current record on the the form,
Next Time it gives me a new Sale Id number.

For Example :
i m entring Data:

Sale Id : 56
Customer Name: Abc
Sales Details: XYZ


Now I Cancel It, Dont save the record, Close the form,

But Now when I will open the form The SaleId Will Put the No 57 in the field
while I have not saved any data on Sale Id no 56.


That's not really a problem and AutoNumber fields have a
similar "problem". The bigger problem is when you have two
or more users doing the same thing, they could both get the
same SaleID number. Another issue with doing it in the Load
(or Current) event is that you dirty the record so you
create blank records when a user decides that is not what
they meant to do.

A popular solution to all those issues is to put that code
in the form's BeforeUpdate event.
 
M

Marshall Barton

Malik said:
I Have a Sale Invoice Form, which has a SaleID TextBox, This Field
automatically generate the next number on a new sale Invoic. I m using the
following script for this fiels :

in Form Load Event
Me!SaleID = NZ(DMax("[SaleID]", "[tablename]")) + 1
. . .

Oops. I meant to include the BeforeUpdate code:

If Me.NewRecord Then
Me.SalesID = Nz(DMax("SaleID", "tablename"), 0) + 1
End If
 
M

Mike Painter

An invoice usually implys a subform.
When you move from the main form to the subform things get saved.
In any event you should examine your "tablename" (not very helpful) and see
if records are being saved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top