how do i set a field to be the same as the the previous +1

J

John

I am inputing data via a form and often the first field (BatchNumber) is
sequential. So i need to set the default value to the previous record +1. I
am using the following code BUT it only works for the next record not 3rd 4th
etc.

Private Sub BatchNumber_AfterUpdate()
BatchNumber.DefaultValue = Me.BatchNumber + 1
End Sub

PS I am new to this

JOHN
 
L

luan

I am inputing data via a form and often the first field (BatchNumber) is
sequential. So i need to set the default value to the previous record +1. I
am using the following code BUT it only works for the next record not 3rd 4th
etc.

Private Sub BatchNumber_AfterUpdate()
BatchNumber.DefaultValue = Me.BatchNumber + 1
  End Sub

PS I am new to this

JOHN

Hi !
Try use BeforeInsert event of the form
me.BatchNumber = Dmax("BatchNumber", "Table contents BatchNumber
field") + 1
Other solution: use AutoNumber for this field.
HTH
Luan
 
L

Linq Adams via AccessMonster.com

The problem is that the AfterUpdate event of a textbox only fires if you
**physically** enter data into it, i.e. type in the date or (I believe) Paste
it in. I got your code to work by adding this code in the form's Dirty event,
to force a firing of the

BatchNumber_AfterUpdate()

after the form is dirty. So when you first move to a new record, the value
for BatchNumber that shows will be the same as the previous record, but after
entering anything else in the record, it will change to be one more than the
last one. So keep your original code, and add this sub:


Private Sub Form_Dirty(Cancel As Integer)
BatchNumber_AfterUpdate
End Sub
 
J

Jason

What about drop down lists in combo boxes - my afterupdates work fine even
if the combo box already contained the exact same text.
 

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