Solved

Memo field update

Posted on 2013-01-28
9
554 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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 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: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

SendBlaster Pro 4 - Bulk Email Sending Software

SendBlaster 4 Pro - Best Bulk Emailing Sending Software
Automatic Subscribe / Unsubscribe Processing
Great for Newsletters & Mass Mailings
Optional HTML & Text Composition
Integration with Google Features
Built in Spam Score Checking
Free Professional Templates - Feature Packed!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Way to transfer 29 56
Excel VBA Script 9 50
ACCESS / VBA - Count of Rows in Table 4 34
Speed up Select Top n... Query 9 30
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

738 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