Eljefegeneo
Still trying to learn
- Local time
- Yesterday, 18:09
- Joined
- Jan 10, 2011
- Messages
- 902
I have a memo field on a form to which I want to add a day and user stamp every time I add some additional text. Originally I had the following code which would add a date but not a user name. It seemed to work fine. But did not add a user name, only a date stamp.
Orginal code: (that worked fine, regardless of any imported text)
If Notes = "" Or IsNull(Me.Notes.OldValue) Then
Me.Notes = Date & " " & Me.Notes & vbCrLf
Else
Me.Notes = Left(Me.Notes, Len(Me.Notes.OldValue)) & _
" " & Date & " " & Right(Me.Notes, Len(Me.Notes) - Len(Me.Notes.OldValue)) & vbCrLf
End If
Me.Dirty = False
Then I figured out how to get a user name which is added to the form on current, depending upon who is the user. An unbound control UserName which I used my code (=FindUserName()) wouldn't do anything to the new code, so I added another text box User which was populated by the UserName control. I am not sure if this was necessary or not, but it did seem to work … but only for some records. The code works fine for any new text added to the memo field, but only if it was originally blank, or was blank to start and then I added some code. If there were some text in the memo field that I imported from another database, I get errors or some crazy addition to the memo field.
This is an example of how it works fine, originally there was no text in the memo field:
12/1/2012 (Gene
12/1/2012 so why not? (Gene
12/1/2012 this should stil work (Gene
Note in the above, I had to copy each line individually, it wouldn't copy all three lines at once. And it never added the final ")" even though it is in the memo field … another mystery.
New code to add the user name:
Private Sub Notes_AfterUpdate()
If Notes = "" Or IsNull(Me.Notes.OldValue) Then
Me.Notes = Date & " " & Me.Notes & " " & "(" & User & ")" & " " & vbCrLf
Else
Me.Notes = Left(Me.Notes, Len(Me.Notes.OldValue)) & _
" " & Date & " " & Right(Me.Notes, Len(Me.Notes) - Len(Me.Notes.OldValue)) & " " & "(" & User & ")" & " " & vbCrLf
End If
Me.Dirty = False
End Sub
Some of the errors I get when there is text in the field imported from the old DB.
Example 1: 12/1/2012
this will not work correctly (Gene (note that there was a carriage return after the date.)
Example 2: Exa 12/1/2012 mple 1 text (Gene (note the split text)
So what I can't figure out is why, if there was some text originally in the memo field that was imported from an old DB, and it is just text, why I get all these errors. The following GotFocus() code won't work in the memo field that has the imported text. It will work find on any memo field that did not have any imported text, whether it is the first time or any subsequent time.
Private Sub Notes_GotFocus()
Me!Notes.SelStart = Me!Notes.SelLength
End Sub
So, the conundrum is why if there is imported text, the code doesn't work properly? And as a sideline, why can't I copy and paste the text from the memo field in its entirely? But this second question is of little or no importance unless it hampers copying the text into a report.
Orginal code: (that worked fine, regardless of any imported text)
If Notes = "" Or IsNull(Me.Notes.OldValue) Then
Me.Notes = Date & " " & Me.Notes & vbCrLf
Else
Me.Notes = Left(Me.Notes, Len(Me.Notes.OldValue)) & _
" " & Date & " " & Right(Me.Notes, Len(Me.Notes) - Len(Me.Notes.OldValue)) & vbCrLf
End If
Me.Dirty = False
Then I figured out how to get a user name which is added to the form on current, depending upon who is the user. An unbound control UserName which I used my code (=FindUserName()) wouldn't do anything to the new code, so I added another text box User which was populated by the UserName control. I am not sure if this was necessary or not, but it did seem to work … but only for some records. The code works fine for any new text added to the memo field, but only if it was originally blank, or was blank to start and then I added some code. If there were some text in the memo field that I imported from another database, I get errors or some crazy addition to the memo field.
This is an example of how it works fine, originally there was no text in the memo field:
12/1/2012 (Gene
12/1/2012 so why not? (Gene
12/1/2012 this should stil work (Gene
Note in the above, I had to copy each line individually, it wouldn't copy all three lines at once. And it never added the final ")" even though it is in the memo field … another mystery.
New code to add the user name:
Private Sub Notes_AfterUpdate()
If Notes = "" Or IsNull(Me.Notes.OldValue) Then
Me.Notes = Date & " " & Me.Notes & " " & "(" & User & ")" & " " & vbCrLf
Else
Me.Notes = Left(Me.Notes, Len(Me.Notes.OldValue)) & _
" " & Date & " " & Right(Me.Notes, Len(Me.Notes) - Len(Me.Notes.OldValue)) & " " & "(" & User & ")" & " " & vbCrLf
End If
Me.Dirty = False
End Sub
Some of the errors I get when there is text in the field imported from the old DB.
Example 1: 12/1/2012
this will not work correctly (Gene (note that there was a carriage return after the date.)
Example 2: Exa 12/1/2012 mple 1 text (Gene (note the split text)
So what I can't figure out is why, if there was some text originally in the memo field that was imported from an old DB, and it is just text, why I get all these errors. The following GotFocus() code won't work in the memo field that has the imported text. It will work find on any memo field that did not have any imported text, whether it is the first time or any subsequent time.
Private Sub Notes_GotFocus()
Me!Notes.SelStart = Me!Notes.SelLength
End Sub
So, the conundrum is why if there is imported text, the code doesn't work properly? And as a sideline, why can't I copy and paste the text from the memo field in its entirely? But this second question is of little or no importance unless it hampers copying the text into a report.