-----Original Message-----
Monika,
If you mean the ID field is an Autonumber data type, under some
circumstances (for example if the database was ever replicated) where
this would not work. If you add a WhenCreated field to the table,
with its Default Value set to Now() the only way this will cause an
error is if the system clock goes haywire (so, assuming you're not in
Queensland, don't do any data entry on Daylight Saving night!) And
no, this field doesn't need to show on your forms or reports.
As regards getting the required data into your new record, there are
many approaches to this. Here's one, which uses a couple of domain
aggregate functions, which is not the most elegant but is possible
relatively intuitive. I am assuming that you at least know how to
enter vba code into an event procedure. So, use the BeforeInsert
property of your form, and do something like...
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim LastEntry As Date
Dim LastJob as Long
LastEntry = DMax("[WhenCreated]","Activities")
LastJob = DLookup("[JobNumber]","Activities", _
"[WhenCreated]=#" & LastEntry & "#")
Me.JobNumber = LastJob
EndSub
Having said all this, I wonder whether you are going about this in the
best way. You haven't told us enough about your project to really
know. But it seems like it could be the case that you have Jobs, each
with a JobNumber, and then for each job there are a number of
Activities. Is this right? So the relationship between the Jobs
table and the Activities table is on the basis of the JobNumber,
right? So one of the standard ways of handling such a scenario is to
put your Activities form as a subform on the Jobs form. So you can go
to the record for the Job in question, and then enter any number of
Activities for that Job, and the JobNumber for the Activities will
automatically be entered for you, without you needing to bother with
any code and stuff.
Please post back if you need any more help with any of this.
- Steve Schapel, Microsoft Access MVP
Yes I have a automatic incremental ID Field in this table.
With the When Created date field: that sounds pretty
useful. That can be put straight in the table with Date ()
perhaps even date and time and doesn't have to show up in
forms does it?
.