By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,163 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,163 IT Pros & Developers. It's quick & easy.

Choosing a date from two possibilities

P: 8
I'm trying to populate a form field depending on dates entered.

Specifically, the user will enter DateA, and DateB, with DateC resulting from those two entries. What I want is for DateC to = DateB + 9 months, UNLES DateA + 12 months is greater, in which case DateC would = DateA + 12 months.

The DateA+12 is a new criteria. I was formerly using After_Update with DateB:

Me![DateC] = DateAdd("m", 9 [DateB])

... which worked fine. Do I need an "If DateDiff" type of statement?

Thanks!
Aug 3 '07 #1
Share this Question
Share on Google+
2 Replies


JKing
Expert 100+
P: 1,206
I'm trying to populate a form field depending on dates entered.

Specifically, the user will enter DateA, and DateB, with DateC resulting from those two entries. What I want is for DateC to = DateB + 9 months, UNLES DateA + 12 months is greater, in which case DateC would = DateA + 12 months.

The DateA+12 is a new criteria. I was formerly using After_Update with DateB:

Me![DateC] = DateAdd("m", 9 [DateB])

... which worked fine. Do I need an "If DateDiff" type of statement?

Thanks!
Here's two ways of doing it...

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'Method 1
  3. If DateAdd("m", 12, Me.[DateA]) > DateAdd("m", 9, Me.[DateB]) Then
  4.    Me.[DateC] = DateAdd("m", 12, Me.[DateA])
  5. Else
  6.    Me.[DateC] = DateAdd("m", 9, Me.[DateB])
  7. End If
  8.  
  9. 'Method 2
  10. Me.[DateC] = iif(DateAdd("m", 12, Me.[DateA]) > DateAdd("m", 9, Me.[DateB]), DateAdd("m", 12, Me.[DateA]), DateAdd("m", 9, Me.[DateB]))
  11.  
I didn't test this so it might need tweaking.
Aug 3 '07 #2

P: 8
Woo hoo! Thanks ... I know just enough code to be dangerous. I had something similar to your 1st method, but my syntax was pretty messy.

Thanks!
Here's two ways of doing it...

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'Method 1
  3. If DateAdd("m", 12, Me.[DateA]) > DateAdd("m", 9, Me.[DateB]) Then
  4.    Me.[DateC] = DateAdd("m", 12, Me.[DateA])
  5. Else
  6.    Me.[DateC] = DateAdd("m", 9, Me.[DateB])
  7. End If
  8.  
  9. 'Method 2
  10. Me.[DateC] = iif(DateAdd("m", 12, Me.[DateA]) > DateAdd("m", 9, Me.[DateB]), DateAdd("m", 12, Me.[DateA]), DateAdd("m", 9, Me.[DateB]))
  11.  
I didn't test this so it might need tweaking.
Aug 3 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.