Date Fields

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Email Account
Exchange Server
Since I have in my contact form different dates and each of them is a field, and i have a code where I could state that the date field is a certain date, can I do it where the date field is equal to another date field plus a certain amount of days after that other date field? And is there a code which makes a date field the date of the current day of the year?
 
You can add dates - and you can use Now, today or Date for 'today'. Depending on where you are putting it, you'll either use parens or not: Now() or Now in the formula. Adding is as simple as date + 7 (for 7 days from the date.) When you create the field, use a formula field.
 
Thanks much...I did the following to create the first field to be todays date and the next field 10 days later...and it did it....thanks much

Sub AddCurrentDateFields()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim ObjItem As Object
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
On Error Resume Next

If TypeName(objApp.ActiveWindow) = "Inspector" Then
Set ObjItem = objApp.ActiveInspector.currentItem


ObjItem.UserProperties("Last Status Date") = Now()

ObjItem.UserProperties("Date to Follow- Up") = ObjItem.UserProperties("Last Status Date") + 10

ObjItem.Save
GoTo Leave
End If

Set objSelection = objApp.ActiveExplorer.Selection

For Each ObjItem In objSelection


ObjItem.UserProperties("Last Status Date") = Now()

ObjItem.UserProperties("Date to Follow- Up") = ObjItem.UserProperties("Last Status Date") + 10
ObjItem.Save

Next
Leave:
Set ObjItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 
Forgot to ask......if it is to be one month after the Last Status Date, can we do that instead of +10

And if the Last Status Date is two days before today, can we change Now() to two before?
 
For one month, do you want same day, 1 month ahead (rather than 30 days). You can do it, but you need to get the month value and add 1 to it.

month (ObjItem.UserProperties("Last Status Date")+1 )
Then you need to put it together to restore the full date. I think. It's been awhile since I did something like this.

Try using now() - 2 or Date - 2 to subtract dates.
 
The now()-2 works perfectly but the following does not work:

ObjItem.UserProperties("Date to Follow- Up") = month (ObjItem.UserProperties("Last Status Date")+1 )
 
BTW, you know that instead of using a macro, you can use a formula in a custom field?

--- Edited ---

changed the screenshot to use the correct formula in the field.
 

Attachments

  • custom-field1.png
    custom-field1.png
    14.2 KB · Views: 397
  • custom-field.png
    custom-field.png
    13.4 KB · Views: 429
I don't know what that means...sorry....ps, please see my other post re the moving attachments to folders please
 
The now()-2 works perfectly but the following does not work:

ObjItem.UserProperties("Date to Follow- Up") = month (ObjItem.UserProperties("Last Status Date")+1 )
You need to put the date together - month (ObjItem.UserProperties("Last Status Date")+1 ) & day (ObjItem.UserProperties("Last Status Date")+1 ) & year (ObjItem.UserProperties("Last Status Date")+1 )

i don't know if ObjItem.UserProperties("Last Status Date")+ month(1) would work - probably not, but it does make a nice short formula. :)
 
Thanks again but neither one worked....and as to the long one this is what I tried:
ObjItem.UserProperties("Date to Follow- Up") = Month(ObjItem.UserProperties("Last Status Date") + 1) & Day(ObjItem.UserProperties("Last Status Date") + 1) & Year(ObjItem.UserProperties("Last Status Date") + 1)
 
Try this instead -

DateAdd("m", 1, ObjItem.UserProperties("Last Status Date"))

As long as last status date is a date field, it should work.
 
Thanks so much...it did it perfectly!!!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Outlook 2013 Sorting and grouping on 2 date fields Using Outlook 1
F Outlook 365 Group INBOX by date but not by date and time Using Outlook 1
S Displaying Date Value In Formula Outlook VBA and Custom Forms 6
CWM550 Wrong Date Using Outlook 4
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
R unable to filter tasks when start date is on or before today Using Outlook 3
S Combination Field (Date Format) Outlook VBA and Custom Forms 0
U How can the Received date be edited? Using Outlook 0
D This folder up to date vs all folders up to date Using Outlook 1
S Outlook Macro for [Date][Subject] Using Outlook 1
N Save emails within a certain date range to network drive Outlook VBA and Custom Forms 0
kburrows Reset Date to Keep Tasks from Archiving Using Outlook 9
M Extract "Date sent" from emails (saved to folder using drag and drop) Outlook VBA and Custom Forms 1
DDB VBA to Auto Insert Date and Time in the signature Outlook VBA and Custom Forms 2
P Short Date Format when typing in a task Using Outlook 2
S Change "This Week" flag start date behavior Using Outlook 1
S Archiving and Likely Modified Date Problem Using Outlook 3
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
S Outlook 2016 Arrange tasks by date, additional custom sorting, but still use friendly terms like Today, Tomorrow, This week? Using Outlook 1
L Macro to add Date & Time etc to "drag to save" e-mails Outlook VBA and Custom Forms 17
S save attachment with date & time mentioned inside the file Outlook VBA and Custom Forms 0
Witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
M Sorting by Day in Date Column Advanced Filter BCM (Business Contact Manager) 1
V Date and/or time error in Outlook Form Outlook VBA and Custom Forms 0
S Body text of Email from invite date/time Outlook VBA and Custom Forms 7
V 10 Years calenders -single date together Exchange Server Administration 8
O Export Outlook calendar appointments by filters and date range Outlook VBA and Custom Forms 1
D Add date next to day name in Outlook Today calendar view Using Outlook 1
X If you change expiration date of repeated task it dupplicates Using Outlook 1
D Archive by receive date not working Using Outlook 2
V Making a Date field mandatory in outlook form Outlook VBA and Custom Forms 2
P Auto Insert Current Date or Time into Email Subject Outlook VBA and Custom Forms 2
L Ctrl Alt d date stamp use Using Outlook 1
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Witzker Outlook 2010 Insert Date & Time at the button of an OL contactform in red Using Outlook 2
O Tasks - Is there a postponed date column? Using Outlook 7
J Command Button to stamp a date and time in a textbox in Outlook 2016 Outlook VBA and Custom Forms 3
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
W Save and rename outlook email attachments to include domain name & date received Outlook VBA and Custom Forms 4
F Finding Meetings/Tasks in a date range Using Outlook 1
W Save Outlook attachment in network folder and rename to current date and time Outlook VBA and Custom Forms 18
M Macro to add date/time stamp to subject Outlook VBA and Custom Forms 4
V Changing default date for task follow-up buttons Using Outlook 2
J Old unread emails on current date (MDaemon Server) Using Outlook 1
D Outlook macro with today's date in subject and paste clipboard in body Outlook VBA and Custom Forms 1
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
B Search by date macro Outlook VBA and Custom Forms 0
S set a flag task date as the next weekday Outlook VBA and Custom Forms 4
K Daily task list > show tasks on the exact due date and not on the "current date" Using Outlook 1

Similar threads

Back
Top