jamaarneen
Programmer
Hi,
I am getting sometimes a little confused about when exactly are the BeforeInsert or AfterInsert events of a bound form firing?
Thanks, Ja
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
The firing of the events (starting with Before Insert), [blue]specifically occurs when you first edit a new record![/blue]jamaarneen said:[blue] . . . what does the user have to do, that access should automatic insert a record?[/blue]
Myself said:but if I get the values from another form, and then the values are added by code - not manually, then the BeforeInsert events never fires, and however, the record is added to the table.
So the question is, which event does fires in this case?
How are you adding by code?jamaarneen said:[blue] . . . [purple]and then the values are added by code[/purple] - not manually, . . .[/blue]
[blue] Me!TextboxName = Forms!Formname!Textbox[/blue]
it's actually both. I mean that I'm adding it thru VBA (ye, something like your example), but it's in another form, where then refresh my first form...How are you adding by code?
Forms![i]form1[/i].[i]fieldname[/i] = Me.con_contactID
[code]Forms![i]form1[/i].Refresh
did you mean the first time edited?Don't forget, the events only fire the first time a new record is edited! Thats thru VBA or manually
TheAceMan1[blue said:When you open form1, does the newly added record (with date) show the pencil iconon the record selector?[/blue]![]()
Close . . . but not quite.jamaarneen said:[blue] . . . so that means, that the form1 is now finish with the record added in the 'load' event, and the form1 is ready for adding another new record[/blue]
not exactly. it is not a default value, I'm assigning the value explicitly by code (see further)Your On Load event is setting the Default Value property of your date field. Default Values only occur on a new record line and do not trigger edit mode. Look at it as a new record line with a preset for your date field
Set rs = CurrentDb.OpenRecordset(strTableName, dbOpenDynaset)
With rs
.AddNew
.Fields(strFieldName) = varValueToAdd
.Update
End With
My form isn't a continuous form, so I can't see a new line popping up...When you edit this new line you'll see another new line popup for continuing the addition of new records
Which property line do you mean?can read all about by putting the cursor on the property line and hitting F1
If I remove the refresh line, the values added in form2 will not be entered in the already existing record, and that's annoying.Getting back to the real content, remove the refresh line as it saves as well!
I have put a "message" in the "BeforeInsert" event (not "Update") to test when it fires.Your using VBA not query/SQL to update the customer from form2.
[blue] Set rs = CurrentDb.OpenRecordset(strTableName, dbOpenDynaset)
With rs
.AddNew
.Fields(strFieldName) = varValueToAdd
.Update
End With[/blue]
[blue] Me![[purple][B][I]strFieldName[/I][/B][/purple]].DefaultValue = "=Date()"[/blue]
No!jamaarneen said:[blue]p.s., Are there any HOT KEYS to insert the TGML tag coding???[/blue]
[blue] DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdRecordsGoToNew[/blue]