Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
How can I increment the date field by 1? Assuming the best way to do this is a macro then how do i finish this sub...
sub inc()
set f = ActiveDocument.GetField ("Date")
f.select ???????
End sub
I wouldn't mess with VB functions. Easier to use QV functions with Evaluate().
'Select today.
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("today(1)")
'Select tomorrow
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("date(today(1)+1)")
'Select 5 days from current selection.
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("date(only(Date)+5)")
-Rob
By increment the date, do you mean select tomorrow?
If so, you can use the VBScript function DateAdd: f.select DateAdd("d", 1, Day())
I tried to test it out and my fields have timestamps, which didn't want to cooperate. This should work fine if your values are dates only.
No i mean more broadly increment by n days.
Using your code I get an error on the
f.
select DateAdd("d", 1, Day())
Wrong number of arguments or invalid property assignment: 'Day'
Thanks
Alkaline wrote:i mean more broadly increment by n days
A date is stored as number of days since the epoch date. To increment by n days, add n.
-Rob
Yes which is what (in principle) that code does.
But to clarify, the code doesn't work and I'm not sure why:
sub inc()
set f = ActiveDocument.GetField ("Date")
f.select DateAdd("d", 1, Day())
End sub
i tried this instead
f.select DateAdd("d", 1, Day(myselection.Item(0).text))
That compiles, but it doesn't change the date
I'm sorry, the VB Script function is Date() not Day().
As Rob said, you probably don't need to bother with DateAdd (old habit). Just add, so: f.Select Date() + n.
I wouldn't mess with VB functions. Easier to use QV functions with Evaluate().
'Select today.
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("today(1)")
'Select tomorrow
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("date(today(1)+1)")
'Select 5 days from current selection.
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("date(only(Date)+5)")
-Rob
Hi,
I have a problem similar to this, but couldn't solve it with your tips (yet).
Could you have a look?
http://community.qlik.com/forums/t/31069.aspx
Thanks,