Connecting Tech Pros Worldwide Help | Site Map

What is the event that occurs right after a record number is generated?

Member
 
Join Date: Aug 2008
Posts: 54
#1: 2 Weeks Ago
I'm trying to trigger some code to fire right after a user enters their first character into any field in the record. I can't seem to identify the proper event. I'm having a little difficulty understanding the difference between an "Update" and an actual post to the table. Here's what I think I know, and don't know:

User types first character into any field in record...

BeforeInsert: Occurs before the autonumber field creates a number.
<unknown event>: Occurs immediately after the autonumber field creates a number.

User leaves the record:
BeforeUpdate: Occurs just before the record is updated to the table.
AfterUpdate: Occurs just after the record is updated to the table.

AfterInsert: Occurs after record is inserted into table. (How is this different from AfterUpdate?)

If you can help me identify the <unknown event>, I'd appreciate it.
Thanks,
Adam
best answer - posted by Megalog
Sorry I think I misread your post.. I was assuming you were trying to work with the autonumber data itself. The OnDirty event is probably what you are looking for, as OB suggested.

If you're trying to fire off your code for a specific condition, say a new record, then you can always add something like this to your OnDirty event:

Expand|Select|Wrap|Line Numbers
  1. If Me.NewRecord Then
  2.   <your function call>
  3. End If
Site Addict
 
Join Date: Mar 2007
Location: Oakland, California, USA
Posts: 521
#2: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


The OnDirty Event for the form should work.
Megalog's Avatar
Expert
 
Join Date: Sep 2007
Posts: 268
#3: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


Adam, can you explain why you're hunting for this event? As far as I know, there isnt an event tied to the autonumber generation.. it's just behind the scenes or parrallel to the OnDirty event. The OnDirty event may not be what you're looking for either, since the autonumber doesnt exist as a value yet when the event first occurs.

Give us a bit more information on what your objective is and we'll be able to help you out more.
Megalog's Avatar
Expert
 
Join Date: Sep 2007
Posts: 268
#4: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


Sorry I think I misread your post.. I was assuming you were trying to work with the autonumber data itself. The OnDirty event is probably what you are looking for, as OB suggested.

If you're trying to fire off your code for a specific condition, say a new record, then you can always add something like this to your OnDirty event:

Expand|Select|Wrap|Line Numbers
  1. If Me.NewRecord Then
  2.   <your function call>
  3. End If
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,209
#5: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


I'm not sure if this is actually relevant in this case, but if you wanted to fire an Event every time that a Character is entered into a Text Box on a Form, then you can use the Change() Event of the Control. For instance, running the following code within the Change() Event of a Text Box Control named Text15, when the User typed Bytes is for me! will result in:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text15_Change()
  2.   Debug.Print Me![Text15].Text
  3. End Sub
Expand|Select|Wrap|Line Numbers
  1. B
  2. By
  3. Byt
  4. Byte
  5. Bytes
  6. Bytes 
  7. Bytes i
  8. Bytes is
  9. Bytes is 
  10. Bytes is f
  11. Bytes is fo
  12. Bytes is for
  13. Bytes is for 
  14. Bytes is for m
  15. Bytes is for me
  16. Bytes is for me!
Member
 
Join Date: Aug 2008
Posts: 54
#6: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


Thanks all,

Dirty is OK, but it's not exactly what I was looking for. Dirty will fire whenever a change occurs on the form, so it will fire when anyone enters a new record AND when anyone edits an existing record.

I'm looking for an event that only fires immediately after a new record is created, but not yet updated. I suppose I could use an "if" statement to weed out all the Dirty events that occur during an edit, but I'm surprised a more specific event doesn't address this.

-Adam
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#7: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


If the new record generates an autonumber you could fire the event in the AfterUpdate event of that control. This will fire as soon as the record is generated which I think (I'm open to correction :D) is triggered as soon as a new record is created in the table.

Funny I was only discussing this with NeoPa last week and he was more up on this event trigger than me so I might ask him to weigh in here.

Mary
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,662
#8: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


It seems that most of the relevant events have already been covered here. This only leaves me the Form_AfterInsert event to recommend.

Dig through Help for a full explanation including limitations (You cannot abort from the Form_AfterInsert, etc).
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,662
#9: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


Scratch that. I've read through the thread again I realise now you are attempting to put in some code between the creation of the AutoNumber value and the new record itself (and also you mentioned the Form_AfterInsert event in your OP anyway). The bad news (for you) is that there is (quite sensibly - It's not really something I can imagine anyone should have access to) no way to interfere at this point. Access must guarantee certain things about records with AutoNumbers which it would not be in such a position to do if random code were allowed to run between the creation of the value and the record. Form_AfterInsert is still there for grabbing the data as soon as it's created. It simply doesn't do it before the record is created (for the reasons described above).

It would be interesting to hear what you had in mind for this event anyway Adam.
Member
 
Join Date: Aug 2008
Posts: 54
#10: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


Here's what I was doing:

I'm using my Access database to create text files that I upload to another database - a commercial database that I have no control over. Most people submit their data to this commercial database manually. I need to do this in volume.

Most people track their records on this database by a name or title they give it. I wanted to create a name based on the record number, so later, I could simply download my records from this commercial database, and match it back to the original records I created in Access.

My original idea was this: While enter data into the form, each time I create a new record number, run a custom function that generates a code-name using the record number - so I would be certain I wasn't uploading duplicate names to the commercial database. In essense, each time a new record number is created, run a function that returns a code-name based on the record number, and put it in a field on the form - then continue entering more info into the form.

I know, I know - I'm making a data field that's based on another field - but since I could not make changes to the name once it was uploaded, I figured it would work out.

I know there are other ways to do this - I could have used an AfterUpdate event on any field - but since I couldn't be sure if the user was going to enter all the data (they might not enter the field i set the trigger on), I thought a trigger based on immediate record creation would be best - and I thought this would be simple. When I noticed that the event I was using didn't work, I began looking at the other events and I began to realize that none of the events exactly fit. I consider myself an intermediate Access developer, and I figured I was missing something, so I tossed the question out here.

I've since created a work around, but I still wanted to explore this because I've run into it before. I'm sure there is a way to do this and I just don't know it.

-Adam
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,991
#11: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


Quote:

Originally Posted by msquared View Post

If the new record generates an autonumber you could fire the event in the AfterUpdate event of that control. This will fire as soon as the record is generated

It's really good to have you back, Mary! Since you're open to correction, I'll do just that! Since the Autonumber field is not populated by physically entering data, the control's AfterUpdate event won't fire. You'd have to explicitly call the AfterUpdate event, and then we'd be right back where we started, looking for an event to fire it in.

Quote:

Originally Posted by AdamOnAccess View Post

Dirty will fire whenever a change occurs on the form, so it will fire when anyone enters a new record AND when anyone edits an existing record.

Megalog's code showed you how to have the function fire in the OnDirty event only if you're dealing with a new record.

Quote:

Originally Posted by Megalog View Post

Expand|Select|Wrap|Line Numbers
  1. If Me.NewRecord Then
  2.   <your function call>
  3. End If

Linq ;0)>
Member
 
Join Date: Aug 2008
Posts: 54
#12: 2 Weeks Ago

re: What is the event that occurs right after a record number is generated?


Me.NewRecord!!!!

I missed it! Bravo!!!

Megalog, thanks for the answer!
Linq, thanks for showing me that I need to read the code more carefully! :)

... and thank you all for the help!

-Adam
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#13: 1 Week Ago

re: What is the event that occurs right after a record number is generated?


Quote:

Originally Posted by missinglinq View Post

It's really good to have you back, Mary! Since you're open to correction, I'll do just that! Since the Autonumber field is not populated by physically entering data, the control's AfterUpdate event won't fire. You'd have to explicitly call the AfterUpdate event, and then we'd be right back where we started, looking for an event to fire it in.


Shucks! I just knew I was wrong. Oh well, it had to happen some time :D

Nice to be back.

Mary
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,991
#14: 1 Week Ago

re: What is the event that occurs right after a record number is generated?


I've made mistakes before, too, Mary!

Just ask my three ex-wives!

Linq ;0)>

P.S. It really is good seeing you back with us!

You've been much on my mind of late!
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#15: 1 Week Ago

re: What is the event that occurs right after a record number is generated?


Quote:

Originally Posted by missinglinq View Post

I've made mistakes before, too, Mary!

Just ask my three ex-wives!

Linq ;0)>

P.S. It really is good seeing you back with us!

You've been much on my mind of late!

We'll catch up soon :)
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,662
#16: 1 Week Ago

re: What is the event that occurs right after a record number is generated?


Quote:

Originally Posted by AdamOnAccess View Post

Here's what I was doing:

...

-Adam

Thanks for the update Adam.

There aren't many explanations for wanting that which would make much sense. I'm happy to say that it seems yours does ;) It's easy to assume because something is rare that the OP is just getting confused, but I'm pleased to see that's not so (and particularly that I wasn't suckered into the assumption).

I'm glad Linq picked up on the idea you possibly hadn't caught MegaLog's post. I wondered a little at the time, but it didn't occur to me to check with you until I saw this explanation and had a better idea of where you were coming from.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,662
#17: 1 Week Ago

re: What is the event that occurs right after a record number is generated?


Quote:

Originally Posted by missinglinq View Post

P.S. It really is good seeing you back with us!

You've been much on my mind of late!

Sorry I couldn't let you know it was coming Linq. The Dragon Queen has been on the verge a few times recently and when I've said to expect her soon she hasn't appeared. I'm just very glad she is now :)
Reply


Similar Microsoft Access / VBA bytes