Solved

Memo field update

Posted on 2013-01-28
9
530 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:hbatt
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

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

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38827402
0
 

Author Comment

by:hbatt
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 500 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:hbatt
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:hbatt
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

805 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