Add a date stamp to the note field of a custom form

0

007

I am using the following code to add a button that inserts a time and date
field in the note section of a custom contact form.

Sub StampDate()
Item.Body = Now() & vbCrLf & vbCrLf & Item.Body
End Sub

Sub CommandButton3_Click()
Call StampDate()
End Sub

There are a few bugs I need to fix.
1) I would like to add the user name.
2) My note field has some files that I have dragged to the top of the note
field and when I click the command button, the date text gets jumbled up
around the files. So I would like the date stamp to be inserted below the
files at the top.

Any help would be greatly appreciated.
 
B

brightenmyoutlook

I am using the following code to add a button that inserts a time and date
field in the note section of a custom contact form.

Sub StampDate()
Item.Body = Now() & vbCrLf & vbCrLf & Item.Body
End Sub

Sub CommandButton3_Click()
Call StampDate()
End Sub

There are a few bugs I need to fix.
1) I would like to add the user name.
2) My note field has some files that I have dragged to the top of the note
field and when I click the command button, the date text gets jumbled up
around the files. So I would like the date stamp to be inserted below the
files at the top.

Any help would be greatly appreciated.
++++++++++++++++++++++++++++++++++++++++++++++++++++++

The modified code below should return the User Name for you.

Sub StampDate()
Item.Body = Application.GetNamespace("MAPI").CurrentUser & " - " &
Now() & vbCrLf & vbCrLf & Item.Body
End Sub

Sub CommandButton3_Click()
Call StampDate()
End Sub


As far as the attachments are concerned, you should place them at the
bottom of the note field. If they must remain on the top, then you
will have to write some code that removes all existing attachments,
inserts your date/time stamp, then adds attachments back into note
field. You can use the code below as a starting point although I
believe this is more effort than its worth.

Sub CopyAttachments (objSourceItem, objTargetItem)
Dim fso As Object
Dim fldTemp As Object
Dim objAtt As Attachment
Dim strPath As String
Dim strFile As String

Set fso = CreateObject ("Scripting.FileSystemObject")
Set fldTemp = fso.GetSpecialFolder(2)
strPath = fldTemp.Path & "\"
For Each objAtt In objSourceItem.Attachments
strFile = strPath & objAtt.FileName
objAtt.SaveAsFile strFile
objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
fso.DeleteFile strFile
Next objAtt

Set objAtt = Nothing
Set fldTemp = Nothing
Set fso = Nothing
End Sub


The modified code below should return the user for you.

Sub StampDate()
Item.Body = Application.GetNamespace("MAPI").CurrentUser & " - " &
Now() & vbCrLf & vbCrLf & Item.Body
End Sub

Sub CommandButton3_Click()
Call StampDate()
End Sub


As far as the attachments are concerned, you should place them at the
bottom of the note field. If they must remain on the top, then you
will have to write some code that removes all existing attachments,
inserts your date/time stamp, then adds attachments back into note
field. You can use the code below as a starting point although I
believe this is more effort than its worth.

Sub CopyAttachments (objSourceItem, objTargetItem)
Dim fso As Object
Dim fldTemp As Object
Dim objAtt As Attachment
Dim strPath As String
Dim strFile As String

Set fso = CreateObject ("Scripting.FileSystemObject")
Set fldTemp = fso.GetSpecialFolder(2)
strPath = fldTemp.Path & "\"
For Each objAtt In objSourceItem.Attachments
strFile = strPath & objAtt.FileName
objAtt.SaveAsFile strFile
objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
fso.DeleteFile strFile
Next objAtt

Set objAtt = Nothing
Set fldTemp = Nothing
Set fso = Nothing
End Sub

Brian McOutlook
www.brightenmyoutlook.com | Outlook Customization
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top