user3221132
user3221132

Reputation:

Why can't I get DateAdd() to work in VBA MS Access

As typical MS Access is making simple things hard...

The two lines:

  now = now()
  twoYearsAgo = DateAdd("m", -24, now)

produces the error on the second line:

 Object Required

Before it also had an error about an array...

Upvotes: 0

Views: 522

Answers (2)

Gustav
Gustav

Reputation: 56026

You are effectively doing:

now = now

So do like this:

Dim ThisMoment As Date
Dim TwoYearsAgo As Date

ThisMoment = Now
TwoYearsAgo = DateAdd("m", -24, ThisMoment )

Upvotes: 1

JJ32
JJ32

Reputation: 1034

There are a number of reserved words, properties in Access VBA. This might help:

Problem names and reserved words in Access

Upvotes: 2

Related Questions