Auto Numbering

N

Nigel

I want to be able to increase my ID field for each new record I enter, but I
don't want to use an autonumber field in my table. I have used the following:
ID = Nz(DMax("[id]", "tblNames")) + 1
and put it in the On Current property of the form. The problem is that when
the last field is completed and the user presses Enter, the new record
automatically puts in the new ID number. What I want to do is for the form to
put in the next ID number but only when the 2nd field has data entered in it.

Thanks
 
M

Mark A. Sam

Nigel,

Place your code into the AfterUpdate event of the second field.

God Bless,

Mark A. Sam
 
N

Nigel

Thanks Mark, just what I wanted.

Nigel

Mark A. Sam said:
Nigel,

Place your code into the AfterUpdate event of the second field.

God Bless,

Mark A. Sam



Nigel said:
I want to be able to increase my ID field for each new record I enter, but
I
don't want to use an autonumber field in my table. I have used the
following:
ID = Nz(DMax("[id]", "tblNames")) + 1
and put it in the On Current property of the form. The problem is that
when
the last field is completed and the user presses Enter, the new record
automatically puts in the new ID number. What I want to do is for the form
to
put in the next ID number but only when the 2nd field has data entered in
it.

Thanks
 
R

Rick Brandt

Nigel said:
Thanks Mark, just what I wanted.

That will work as long as you will never have more than one person entering
records at the same time. If you do you need to use the BeforeUpdate event of
the form and test for the NewRecord property.

Actually you need to test for the NewRecord property the way you are doing it as
well. Otherwise if someone edits the second field on an existing record the
number will be reassigned.
 
C

croy

I want to be able to increase my ID field for each new record I enter, but I
don't want to use an autonumber field in my table. I have used the following:
ID = Nz(DMax("[id]", "tblNames")) + 1
and put it in the On Current property of the form. The problem is that when
the last field is completed and the user presses Enter, the new record
automatically puts in the new ID number. What I want to do is for the form to
put in the next ID number but only when the 2nd field has data entered in it.


This may not be the best for your situation, but it's worth
a thought...

Use your code to set DefaultValue instead of the Value.
Certainly not foolproof, but if your data-entry folks have
good understanding, and good discipline...
 
K

Keith Wilby

croy said:
I want to be able to increase my ID field for each new record I enter, but
I
don't want to use an autonumber field in my table. I have used the
following:
ID = Nz(DMax("[id]", "tblNames")) + 1
and put it in the On Current property of the form. The problem is that
when
the last field is completed and the user presses Enter, the new record
automatically puts in the new ID number. What I want to do is for the form
to
put in the next ID number but only when the 2nd field has data entered in
it.


This may not be the best for your situation, but it's worth
a thought...

Use your code to set DefaultValue instead of the Value.
Certainly not foolproof, but if your data-entry folks have
good understanding, and good discipline...

Default Value, I agree. I find the best way to implement that code is via a
"new record" command button - set up the form such that the only way to add
a new record is via your command button and save the record as soon as it is
created. Don't allow users to delete records, allow them to flag them as
deleted and query accordingly.

Keith.
www.keithwilby.com
 
R

Rick Brandt

croy said:
I want to be able to increase my ID field for each new record I
enter, but I don't want to use an autonumber field in my table. I
have used the following: ID = Nz(DMax("[id]", "tblNames")) + 1
and put it in the On Current property of the form. The problem is
that when the last field is completed and the user presses Enter,
the new record automatically puts in the new ID number. What I want
to do is for the form to put in the next ID number but only when the
2nd field has data entered in it.


This may not be the best for your situation, but it's worth
a thought...

Use your code to set DefaultValue instead of the Value.
Certainly not foolproof, but if your data-entry folks have
good understanding, and good discipline...

Also will not work with multiple users entering records simutaneously.
 

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