?
Solved

Memo field update

Posted on 2013-01-28
9
Medium Priority
?
566 Views
Last Modified: 2013-01-28
Hi Experts,
I have added a user name and time stamp to a memo field as an "after update" event.  The code works when something is added, but also is fired when something is deleted, which I don't want. Could someone please modify the attached code so that it is only fired when something is added?
Thanks experts!
Private Sub Notes_AfterUpdate()
   
    Me.Notes = Me.Notes & " (added by " & fOSUserName & " on " & Now() & ")" & vbCrLf
    
End Sub

Open in new window

0
Comment
Question by:Harry Batt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 38827243
What you are asking is pretty well impossible unless you are saying that you have specific separate procedures for adding content and deleteing content.

There is no way to tell whether content was changed, added or deleted unless you get involved in some very sophisticated character matching - all you can tell is that something was done to the text.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38827266
what version of access are you using?
0
 
LVL 77

Expert Comment

by:peter57r
ID: 38827302
I suppose that if you did something like...

Me.Notes = Me.Notes & " (added by " & fOSUserName & " on " & Now() & ") ***" & vbCrLf

then you could test for the presence of *** in the last, say, 7 characters and if found , do not append the username and timestamp.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Harry Batt
ID: 38827340
I am using Access 2007
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38827402
0
 

Author Comment

by:Harry Batt
ID: 38827583
I find that the ColumnHistory method also appends the code with the user name and date when data is being deleted, so unless I am wrong, I don't believe this is a viable solution. I haven't tried Peter57's character matching solution, but if this is the optimal way of handling this issue, what would the code look like?
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 38827612
can you try using

if len(me.notes).oldvalue > len(me.notes).value  then  'this means that something was deleted
0
 

Author Comment

by:Harry Batt
ID: 38827871
Capricorn1,

With a slight modification, this works.  (The .value expression triggered an error)

Thanks!
Private Sub Notes_AfterUpdate()
    If Len(Me.Notes.OldValue) > Len(Me.Notes) Then 'this means that something was deleted
        Exit Sub
    Else

    Me.Notes = Me.Notes & " (added by " & fOSUserName & " on " & Now() & ")" & vbCrLf
    
    End If
End Sub

Open in new window

0
 

Author Comment

by:Harry Batt
ID: 38828154
One change to correct a bug when deleting:
Private Sub Notes_AfterUpdate()
   
    If Len(Me.Notes.OldValue) > Len(Me.Notes.Value) Then 'this means that something was deleted
    
        Exit Sub
    Else
 If Me.Dirty Then Me.Dirty = False
    Me.Notes = Me.Notes & " (added by " & fOSUserName & " on " & Now() & ")" & vbCrLf
    
    End If
   
End Sub

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question