VBA to populate a field with Date +7 Days

Ian Wright

Registered User.
Local time
Today, 01:34
Joined
Oct 20, 2007
Messages
28
Help please, I am struggling to auto populate a field upon loss focus of another field. I want current date + 7 days. I have tried using:

NCD1 = DateAdd(d, 7, Date)

and get runtime error 5 - Invalid procedure call or argument

From what I have seen on the web there should be a () after the "Date" but Access 2007 removes these when I accept the line.

I have checked with just Date, once again () removed by program and it works so the fields are good.

I would be most obliged if someone would help. :banghead:

Thanks, Ian
 
I assume this is being done in a form. Try:
Me.NCD1 = DateAdd('d', 7, Date)
 
Close...but that'll give you a syntax error...it has to be Double Quotes:

Me.NCD1 = DateAdd("d", 7, Date)

Linq ;0)>
 
Hi Bob,

It wouldn't accept the suggested line the " 'd' ", it would with just a d but I then got the error:

Compile Error - Method or Data Member not found

I tired the original with [Form Name.Field Name] without success too.

Thanks for trying though :O)
 
Hi Chaps,

I've tried the double quotes, and gets the same error msg.

I then knocked off the Me. which runs without an error but leaves the intended reulsts field blank :o(
 
I've tried the double quotes, and gets the same error msg.

That really makes no sense..that is the correct syntax for this (tested and works) at least in the English version of Access! Other language versions do, I believe, use different delimiters for parameters in functions.

When things that patently should work, and don't, you always have to consider corruption. Although we usually think of Forms, or entire Databases, when we speak of corruption, individual Controls, such as Textboxes, can and do become corrupted. The test and the fix are one and the same; deleting the Control then re-creating it! If it was corrupt, you've verified the fact and solved the problem! If not, you've only lost a minute or two!

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom