473,378 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Combining Expressions

Hi,

Here's what I would like to do - I have 3 fields that are relative to one another.

in field 2 i want to put a date, and then i need field 3 to calculate another date that is earlier than the date put in field 2.

for this I am using the following expression - =DateDiff("d",+7,[Field 2])

This works fine, however this is where it gets complicated.

The DateDiff varies depending on what is entered in field one.

If in field 1 I enter the text 1 Month, I need the DateDiff to be for example 7 days. If I enter 4 Months, I need the date diff to be 90 days, If I enter 6 Months I need the DateDiff to be 120 days .....

So you see my problem .... any ideas very gratefully accepted!!!
Dec 14 '07 #1
8 1814
NeoPa
32,556 Expert Mod 16PB
Firstly, you confuse things by saying an earlier date then illustrating with DateDiff("d", +7, ...)
An earlier date would have a negative (-) number there.
For your problem use "Select Case Me.[Field 1]" and assign the value of days different to a variable (intDays).
After that's completed use :
Expand|Select|Wrap|Line Numbers
  1. Me.[Field 3] = DateDiff("d", intDays, Me.[Field 2])
Dec 14 '07 #2
Firstly, you confuse things by saying an earlier date then illustrating with DateDiff("d", +7, ...)
An earlier date would have a negative (-) number there.
For your problem use "Select Case Me.[Field 1]" and assign the value of days different to a variable (intDays).
After that's completed use :
Expand|Select|Wrap|Line Numbers
  1. Me.[Field 3] = DateDiff("d", intDays, Me.[Field 2])
I really appreciate your help here, -- but I still cant get it to work!!

I'm using a drop down box for field one which has different values - 1 Month, 2 Month, 3 Month.

When a date is entered in field 2 I need field 3 to fill in automatically with an earlier date depending on what is entered in field 1. For 1 month is should show 30 days earlier than the date put in field 2, for 2 month 60 days and 3 month 90 days.

I've tried phone a friend and the computer's already taken away 2 wrong answers .....

Any help greatly appreciated!!
Dec 15 '07 #3
ADezii
8,834 Expert 8TB
I really appreciate your help here, -- but I still cant get it to work!!

I'm using a drop down box for field one which has different values - 1 Month, 2 Month, 3 Month.

When a date is entered in field 2 I need field 3 to fill in automatically with an earlier date depending on what is entered in field 1. For 1 month is should show 30 days earlier than the date put in field 2, for 2 month 60 days and 3 month 90 days.

I've tried phone a friend and the computer's already taken away 2 wrong answers .....

Any help greatly appreciated!!
In the AfterUpdate() Event of Field1:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Field1_AfterUpdate()
  2. If Not IsNull(Me![Field1]) And Not IsNull(Me![Field2]) Then
  3.   Select Case Me![Field1]
  4.     Case "1 Month"
  5.       Me![Field3] = DateAdd("d", -30, Me![Field2])
  6.     Case "2 Months"
  7.       Me![Field3] = DateAdd("d", -60, Me![Field2])
  8.     Case "3 Months"
  9.       Me![Field3] = DateAdd("d", -90, Me![Field2])
  10.     Case Else
  11.       'do nothing
  12.   End Select
  13. End If
  14. End Sub
Dec 15 '07 #4
NeoPa
32,556 Expert Mod 16PB
ADezii's answer is pretty similar to what I was saying. A nice full solution for you too. Make sure when you use it though, that you change the control names to match yours exactly. Me![Field2] =/= Me![Field 2]. We don't have your database to hand so we can only use our best guesses and what you tell us.
Another solution, though a little harder to get your head around, is to have an extra column in the ComboBox and refer to that for the second parameter to the DateAdd() call. You shouldn't need to worry about that though, as your situation seems relatively straightforward (and ADezii has already provided some pretty neat code anyway ;)).
Dec 15 '07 #5
ADezii
8,834 Expert 8TB
In the AfterUpdate() Event of Field1:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Field1_AfterUpdate()
  2. If Not IsNull(Me![Field1]) And Not IsNull(Me![Field2]) Then
  3.   Select Case Me![Field1]
  4.     Case "1 Month"
  5.       Me![Field3] = DateAdd("d", -30, Me![Field2])
  6.     Case "2 Months"
  7.       Me![Field3] = DateAdd("d", -60, Me![Field2])
  8.     Case "3 Months"
  9.       Me![Field3] = DateAdd("d", -90, Me![Field2])
  10.     Case Else
  11.       'do nothing
  12.   End Select
  13. End If
  14. End Sub
I can't believe that I am actually crazy enough to Reply to my own Post, but to actuallly make the code more efficient:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Field1_AfterUpdate()
  2. If Not IsNull(Me![Field1]) And Not IsNull(Me![Field2]) And IsDate(Me![Field2]) Then
  3.   Select Case Me![Field1]
  4.     Case "1 Month"
  5.       Me![Field3] = DateAdd("d", -30, Me![Field2])
  6.     Case "2 Months"
  7.       Me![Field3] = DateAdd("d", -60, Me![Field2])
  8.     Case "3 Months"
  9.       Me![Field3] = DateAdd("d", -90, Me![Field2])
  10.     Case Else
  11.       'do nothing
  12.   End Select
  13. End If
  14. End Sub
Dec 15 '07 #6
NeoPa
32,556 Expert Mod 16PB
I'm not even SURPRISED ;)
Checking that the input conforms to the required format is always a good thing to do thoroughly though. Nice addition.
Dec 16 '07 #7
ADezii
8,834 Expert 8TB
I'm not even SURPRISED ;)
Checking that the input conforms to the required format is always a good thing to do thoroughly though. Nice addition.
I'm not even SURPRISED
I guess after all this time nothing surprises you, right NeoPa (LOL).
Dec 16 '07 #8
NeoPa
32,556 Expert Mod 16PB
Your craziness? - certainly not ADezii :D

BTW Was that an age dig? (I guess, after all this time, ...)
I'm not old!! I'm a very young 47 - LOL.
Dec 16 '07 #9

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

Similar topics

5
by: Andrew Dixon - Depictions.net | last post by:
Hi Everyone. I have been working on some code that strips the HTML code out of an HTML page leaving just the text on the page. At the moment this is what I have: // Strip all tags...
7
by: Paddy McCarthy | last post by:
Hi, I am trying to use eval as little as possible but solve this problem. #If given:two or more lambda equations x=lambda : A < B y=lambda : C+6 >= 7 .... How do I create another lambda...
2
by: Chris Mullins | last post by:
I've spent a bit of time over the last year trying to implement RFC 3454 (Preparation of Internationalized Strings, aka 'StringPrep'). This RFC is also a dependency for RFC 3491...
3
by: alwayswinter | last post by:
I currently have a form where a user can enter results from a genetic test. I also have a pool of summaries that would correspond to different results that a user would enter into the form. I...
7
by: Barry | last post by:
Hi all, I've noticed a strange error on my website. When I print a capital letter P with a dot above, using & #7766; it appears correctly, but when I use P& #0775 it doesn't. The following...
5
by: M.Stanley | last post by:
Hi, I'm attempting to create a query that will combine 2 columns of numbers into one. The followng comes from 1 table with 4 fields (A,B,C,D) A B RESULT 700 000 700000 700 001 ...
1
by: Scott | last post by:
This is probably something really easy, Well I hope anyhow. I have three fields used for barcoding, in one table F1, F2 and F3. I want the three fields to be able to be combined to complete an...
1
by: Dave | last post by:
I am trying to create one RegEx pattern, something like, \s*(?<typename>\S*){1}\s*(?<varname>\S*){1}\s*{1}\s*(?<varvalue>.*)* out of the following 2 expressions and am not having much luck. ...
14
by: frizzle | last post by:
Hi group, I have a function which validates a string using preg match. A part looks like if( !preg_match( '/^(+((*)?)?)$/', $string ) || preg_match( '/(--|__)+/' ,$string) ) { i wonder...
5
by: Tristan Miller | last post by:
Greetings. Is it possible using HTML and CSS to represent a combining diacritical mark in a different style from the letter it modifies? For example, say I want to render Å‘ (Latin small letter...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.