Look up last entry for field and +1

F

Fletcher

Hi, I would like a text box on my form to look up the previous entry
and then add 1 to it. I've been trying real hard at this, but it's
still avoiding me.

What I have now is:

Me!txtPassNumber.DefaultValue = Me!PassNumber.Value + 1

in the AfterUpdate field in the properties of the text box.

For a while this brought up the number 1, but it has since quit doing
that.

If anyone knows what I'm doing wrong, I would greatly appreciate some
direction.

Thanks,

Fletcher.
 
M

Marshall Barton

Fletcher said:
Hi, I would like a text box on my form to look up the previous entry
and then add 1 to it. I've been trying real hard at this, but it's
still avoiding me.

What I have now is:

Me!txtPassNumber.DefaultValue = Me!PassNumber.Value + 1

in the AfterUpdate field in the properties of the text box.

For a while this brought up the number 1, but it has since quit doing
that.

If anyone knows what I'm doing wrong, I would greatly appreciate some
direction.


How is the value in the text box being updated? The
AfterUpdate event is only triggered when a user enters/edits
the text box's value.

The standard approach to assigning a new record the next
available number is to us the **form's** BeforeUpdate event
to set the value:
Me.PassNumber = Nz(DMax("PassNumber", "thetable"),0) +1
 
F

Fletcher

Hi Marsh, Thanks for the data. The only unfortunate thing is that it
didn't work. Also, I'm not looking to add one to the max value, but
rather the last value entered. I tried moving my command to the before
update event of the form, but it did not work either. If you have any
other ideas, I would love to hear them. Thanks again.

Fletcher...

Graham said:
Hi Fletcher

Check back in the other message thread for my ongoing reply.
--
Cheers!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Fletcher said:
Hi, I would like a text box on my form to look up the previous entry
and then add 1 to it. I've been trying real hard at this, but it's
still avoiding me.

What I have now is:

Me!txtPassNumber.DefaultValue = Me!PassNumber.Value + 1

in the AfterUpdate field in the properties of the text box.

For a while this brought up the number 1, but it has since quit doing
that.

If anyone knows what I'm doing wrong, I would greatly appreciate some
direction.

Thanks,

Fletcher.
 
F

Fletcher

Actually, this is becoming unnecessary. Sorry for the trouble. Thanks
for your help.

Fletcher...
Hi Marsh, Thanks for the data. The only unfortunate thing is that it
didn't work. Also, I'm not looking to add one to the max value, but
rather the last value entered. I tried moving my command to the before
update event of the form, but it did not work either. If you have any
other ideas, I would love to hear them. Thanks again.

Fletcher...

Graham said:
Hi Fletcher

Check back in the other message thread for my ongoing reply.
--
Cheers!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Fletcher said:
Hi, I would like a text box on my form to look up the previous entry
and then add 1 to it. I've been trying real hard at this, but it's
still avoiding me.

What I have now is:

Me!txtPassNumber.DefaultValue = Me!PassNumber.Value + 1

in the AfterUpdate field in the properties of the text box.

For a while this brought up the number 1, but it has since quit doing
that.

If anyone knows what I'm doing wrong, I would greatly appreciate some
direction.

Thanks,

Fletcher.
 
Top