Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell between a "New Record" and a "Edited Record" 2

Status
Not open for further replies.

WallT

Vendor
Aug 13, 2002
247
0
0
US
I need some advice here. What is the best way for Access to tell whether an updated record is a new record, or a record that I just edited.

For instance, if I am entering a new order, and after that order updates I will have Access automatically do something with part of the data...however, if I just edited that order, then I don't want Access to do anything.

I have expermented with the OnDirty event, but ity seems to triggered when a record is new or edited.

I know I can just add a field to the Orders table and make it true or something the first time it is created and go from there, but I was thinking there is probably a way that I am not thinking of.

Thanks for any input.
 
Have a look at the NewRecord property of the form object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I tried playing with that a little, but I know I am not using it right...I simply did

If Me.NewRecord = True Then
Do this
Else
Exit Sub
End IF

and a couple other ways that don't work, nor did I expect them to.

How is that property used correctly for my situation?

Thank you for your help.
 
Test it in the BeforeUpdate event procedure of the form.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya WallT . . .
WallT said:
[blue]What is the best way for Access to tell whether an updated record is a new record, or a record that I just edited.[/blue]
New records in access are added in one place only. This is effectively the record after the last displayed record in the form, depicted by the "*" symbol on the record selector. When the cursor resides on this line the New Record property is set to true, false otherwise . . .

Any time you edit a record (new or not) the Dirty property is set to true. With the above the following truth table can be constructed:

[tt][blue]NewRec Dirty Result
****** ***** ****************************************************
False False cursor on previously saved line, user is not editing.
False True cursor on previously saved line, user is editing.
True False cursor on new line, user is not editing.
True True cursor on new line, user is editing.[/blue][/tt]


Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
WallT . . .

Hit submitt too soon!

When you save/update a record the properties revert to not dirty/not new. Your problem is you need to use the forms After update event, however the properties are reset at this time and you can't tell a new record from previously saved.

Enter the BeforeUpdate event. Here the the properties are still set!. So what you can do is set a public variable to be read by the afterupdate event.

Code:
[blue]Public flgNew as Boolean[/blue]
Then in the forms BeforeUpdate event:
Code:
[blue]   flgNew = Me.Newrecord[/blue]
Finally in the forms AfterUpdate event:
Code:
[blue]   If flgNew then
      [green]'code for new record[/green]
   Else
      [green]'code for peviously saved record[/green]
   End If

   flgNew = False[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top