Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / May 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 28 May 2008 00:49 GMT
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
luan - 28 May 2008 03:55 GMT
> 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
[quoted text clipped - 8 lines]
>
> 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
Linq Adams - 28 May 2008 04:01 GMT
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  

>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
[quoted text clipped - 8 lines]
>
>JOHN

Signature

There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Jason - 28 May 2008 09:04 GMT
What about drop down lists in combo boxes - my afterupdates work fine even
if the combo box already contained the exact same text.
> 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
[quoted text clipped - 24 lines]
> >
> >JOHN
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.