473,386 Members | 1,775 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,386 software developers and data experts.

Building an expression

Hello,
I am building a customer database for my friend who has a tanning business.

In my "Enter Customer Info" form I want my text box to return a YES or NO value if the date value entered in another field plus 16 years is before (NO) or after (YES) today's date.
The object is to quickly show if a customer is younger than 16 years old and prompt whomever is entering the information to print a report I've created that is a waiver that must be signed by the customer.
I know it seems easy, but I'm having trouble with the date plus 16 part...
Can anyone help me with this?

Thanks in advance,
Tammy
May 22 '07 #1
22 1564
Rabbit
12,516 Expert Mod 8TB
Hello,
I am building a customer database for my friend who has a tanning business.

In my "Enter Customer Info" form I want my text box to return a YES or NO value if the date value entered in another field plus 16 years is before (NO) or after (YES) today's date.
The object is to quickly show if a customer is younger than 16 years old and prompt whomever is entering the information to print a report I've created that is a waiver that must be signed by the customer.
I know it seems easy, but I'm having trouble with the date plus 16 part...
Can anyone help me with this?

Thanks in advance,
Tammy
Try this:

iif(DateDiff("y", Birthdate, Date) < 16, "YES", "NO")
May 22 '07 #2
missinglinq
3,532 Expert 2GB
Actually, that should be

iif(DateDiff("yyyy", Birthdate, Date) < 16, "YES", "NO")

The single y for interval stands for "day of year" not years.

The problem with this code is that it won't return an accurate age! If it's run on any day in 2007, and the Birthdate is any day in 1991, it will yield an age of 16 and thus return "No." But if the person hasn't yet had a birthday in 2007, they're not yet 16, and it should return "Yes."

This will return the actual age and yield the appropriate Yes or No:

Expand|Select|Wrap|Line Numbers
  1. IIf(DateDiff("yyyy", [Birthday], Date) - IIf(Format$(Date, "mmdd") < Format$([Birthday], "mmdd"), 1, 0) < 16, "Yes", "No") 
  2.  
May 23 '07 #3
Thanks for the help.
I entered the expression and it's returning #Name? in that field.
Not sure what is wrong...
Tammy
May 23 '07 #4
Message deleted by poster. Will post again shortly. Sorry for the delay.
May 24 '07 #5
Message deleted by poster. Will post again shortly. Sorry for the delay.
Try the following in your unbound textbox. This is assuming that the field that contains the date of birth is named "Birthdate" not "Birthday"

also this is based off of the now() function rather than a specified date.

With the example above your date of birth field would have to be named birthday and you needed to change date to a specified date not the word date.

This will compare their birthday to "today"

Expand|Select|Wrap|Line Numbers
  1. IIf(DateDiff("yyyy", [Birthdate], Now())-IIf(Format$(Now(), "mmdd")<Format$([Birthdate], "mmdd"),1,0)<16,"NO","YES")
May 24 '07 #6
missinglinq
3,532 Expert 2GB
You have to replace [Birthday] in my code or [Birthdate] in the version by theaybaras with the actual name of your own textbox.
May 24 '07 #7
Okay.
My field is named Birthdate. I changed Birthday to Birthdate when I entered the code. I was using Date() in my Date field. So I used that in the code also. Is that the problem?
I'm not sure that using Date() in the Date field is what I want anyway. When I open the database, I want the current date to fill in automatically on a new record, but after that date, I don't want it to change to the current date every time I look at the record. How do I accomplish that?
Thanks,
Tammy
May 24 '07 #8
Okay.
My field is named Birthdate. I changed Birthday to Birthdate when I entered the code. I was using Date() in my Date field. So I used that in the code also. Is that the problem?
I'm not sure that using Date() in the Date field is what I want anyway. When I open the database, I want the current date to fill in automatically on a new record, but after that date, I don't want it to change to the current date every time I look at the record. How do I accomplish that?
Thanks,
Tammy
So then, assuming you have a date field that will be storing the date in your table. Go into your table design, and set the default value of this date field to Date(). Then when you create a new record, today's date will fill in automatically, but this will be stored in the table. When you view the record again later, that date will still be there because you are not asking it to compute today's date in a field, you are storing the data in a field just like always... the field was just populated by the default value date().

Does this work for you?
May 24 '07 #9
when you are calculating the clients age... is there a reason you are adding 16 to years to their birthdate rather than just finding the difference between birthdate and date()? I'm just curious as I haven't seen the other approach very often.
May 24 '07 #10
NeoPa
32,556 Expert Mod 16PB
Okay.
My field is named Birthdate. I changed Birthday to Birthdate when I entered the code. I was using Date() in my Date field. So I used that in the code also. Is that the problem?
I'm not sure that using Date() in the Date field is what I want anyway. When I open the database, I want the current date to fill in automatically on a new record, but after that date, I don't want it to change to the current date every time I look at the record. How do I accomplish that?
Thanks,
Tammy
Tammy,
If you set the default for the field (in the table design is better, but it can also be done on the form control) to =Date(), then it will only populate it with that value when it is originally entered.

theAybaras,
It is a good idea always to use the Date() function rather than the Now() function when dealing with dates and date ranges. Typically, next week (from Monday 16th May ????) is Monday 23rd May ???? and not 15:09 on Monday 23rd May ????. This can be important, especially in situations where you're checking date ranges.

Lastly, it is often more straightforward when checking dates, to compare today with a date plus x, rather than subtract the two dates and test the period in between. Consider this case : How would you determine if the difference between the two dates matched 16 years? Which years are leap years? etc.
More reliable to compare Birthdate+16 years (done for you by DateAdd()) with today. If the result is after today, they're < 16 Yrs. Does that make sense.
May 27 '07 #11
That makes a lot of sense! Thanks for the advice! That answers some issues I ahve had in the past! Thanks!

theAybaras
May 28 '07 #12
NeoPa
32,556 Expert Mod 16PB
No problem.
Happy to share experience (Why else would I be here ;)).
May 29 '07 #13
Okay. So you kinda lost me.
Not sure now what I need to enter in my field to get a YES response if the customer is less than 16 years old (or NO if 16 or older)?
Tammy
Jun 5 '07 #14
NeoPa
32,556 Expert Mod 16PB
Okay. So you kinda lost me.
Not sure now what I need to enter in my field to get a YES response if the customer is less than 16 years old (or NO if 16 or older)?
Tammy
OK Tammy,
I think all you need is in post #11.
Set the default in the table design to use Date() (=Date()).
In the query that you want to let you know if someone is 16 or older include :
Expand|Select|Wrap|Line Numbers
  1. SELECT ...
  2.        IIf(DateAdd('yyyy',16,[BirthDate])>Date(),'No','Yes') AS OldEnough,
  3.        ...,
  4. FROM [BlahBlahBlah] etc
Jun 5 '07 #15
I don't have enough experience with expressions or Access for that matter
to be able to see where you're going with this....but I don't think this is all
I need?
=IIf(DateAdd('yyyy',16,[Birthdate])>Date(),'NO','YES')
I guess I'm not following. I'm sorry for being such a pain.
P.S. I did set the default to use Date() and it is working how I want.

OK Tammy,
I think all you need is in post #11.
Set the default in the table design to use Date() (=Date()).
In the query that you want to let you know if someone is 16 or older include :
Expand|Select|Wrap|Line Numbers
  1. SELECT ...
  2.        IIf(DateAdd('yyyy',16,[BirthDate])>Date(),'No','Yes') AS OldEnough,
  3.        ...,
  4. FROM [BlahBlahBlah] etc
Jun 7 '07 #16
NeoPa
32,556 Expert Mod 16PB
I don't have enough experience with expressions or Access for that matter
to be able to see where you're going with this....but I don't think this is all
I need?
=IIf(DateAdd('yyyy',16,[Birthdate])>Date(),'NO','YES')
I guess I'm not following. I'm sorry for being such a pain.
P.S. I did set the default to use Date() and it is working how I want.
OK.
Well, first of all, it's good that you've got the Date() of entry working properly. That's actually the harder part ;)

Now, do you have a query somewhere which needs a Yes/No result depending on the age of a person? You mention a field - where is this? In a query? On a form?
If I can understand exactly what you're trying to do, I'll be in a better position to help you along step by step.
Jun 7 '07 #17
OK.
Well, first of all, it's good that you've got the Date() of entry working properly. That's actually the harder part ;)

Now, do you have a query somewhere which needs a Yes/No result depending on the age of a person? You mention a field - where is this? In a query? On a form?
If I can understand exactly what you're trying to do, I'll be in a better position to help you along step by step.
WooHOO! Thank you SOO much for your help!
I figured it out on my own...it's a field in a form- I had to make the
code look at the necessary fields on the table.. if that makes sense!
Also, I had to change the > to a < to make it calculate properly (it was
returning Yes for ages greater than 16 and No for ages less than 16. I
wanted it to return "yes" for "signature req'd?" for clients less than 16 years old.

Now that I have that figured out, I would like to ask you another
question...
Currently, when you open the database, it opens to the 1st entry.
If my friend wants to open the database and then go to a specific record,
what do I need to do to give her the easiest way to find a specific record
quickly? I assume this search would be based on 1st or last name.
Thanks!
Tammy
Jun 7 '07 #18
NeoPa
32,556 Expert Mod 16PB
WooHOO! Thank you SOO much for your help!
I figured it out on my own...it's a field in a form- I had to make the
code look at the necessary fields on the table.. if that makes sense!
Also, I had to change the > to a < to make it calculate properly (it was
returning Yes for ages greater than 16 and No for ages less than 16. I
wanted it to return "yes" for "signature req'd?" for clients less than 16 years old.

Now that I have that figured out, I would like to ask you another
question...
Currently, when you open the database, it opens to the 1st entry.
If my friend wants to open the database and then go to a specific record,
what do I need to do to give her the easiest way to find a specific record
quickly? I assume this search would be based on 1st or last name.
Thanks!
Tammy
Congratulations. it's always fun when you get something sorted out.
You're right about my code. it was answering the question "Are they 16 or over?"
To answer your last question I'd need to know what type of form you have and what it's bound to. I would guess that it's bound to a table, but what fields are shown and would you want to implement a form of filtering or just do a search (Using the binoculars button)?
Jun 7 '07 #19
NeoPa
32,556 Expert Mod 16PB
Congratulations. it's always fun when you get something sorted out.
You're right about my code. it was answering the question "Are they 16 or over?"
To answer your last question I'd need to know what type of form you have and what it's bound to. I would guess that it's bound to a table, but what fields are shown and would you want to implement a form of filtering or just do a search (Using the binoculars button)?
I was in a hurry leaving work for the last post.
How were you thinking that someone would choose which record they wanted?
Jun 7 '07 #20
I was in a hurry leaving work for the last post.
How were you thinking that someone would choose which record they wanted?
I was thinking that they would search based on names (first & last).
I am using a switchboard. The switchboard opens 1st. From there you can
choose to enter/view client records, preview reports, etc. I was thinking of
adding a button there that would be "search for a client record". Not sure
after that how it would function. I am using a form to enter data into a table.
I want the search to open the form to the record of the person they are
searching for.
Tammy
Jun 7 '07 #21
NeoPa
32,556 Expert Mod 16PB
In that case I would say that you have two options :
  1. First Option
    1. Create an unbound TextBox control on your form (We'll call it txtSearch).
    2. In the After_Update event procedure have :
      Expand|Select|Wrap|Line Numbers
      1. Private Sub txtSearch_AfterUpdate()
      2.   With Me.Recordset
      3.     Call .FindFirst("[YourNameField] Like '" & Me.txtSearch & "*'")
      4.     If .NoMatch Then Call MsgBox("No record found!")
      5.   End With
      6. End Sub
  2. Second Option
    1. Create an unbound ComboBox control on your form which lists all the records in the recordset (The same records that the form can select from - We'll call it cboSearch).
    2. In the After_Update event procedure have :
      Expand|Select|Wrap|Line Numbers
      1. Private Sub cboSearch_AfterUpdate()
      2.   Call Me.Recordset.FindFirst("[YourNameField]='" & Me.cboSearch & "'")
      3. End Sub
Jun 7 '07 #22
In that case I would say that you have two options :
  1. First Option
    1. Create an unbound TextBox control on your form (We'll call it txtSearch).
    2. In the After_Update event procedure have :
      Expand|Select|Wrap|Line Numbers
      1. Private Sub txtSearch_AfterUpdate()
      2.   With Me.Recordset
      3.     Call .FindFirst("[YourNameField] Like '" & Me.txtSearch & "*'")
      4.     If .NoMatch Then Call MsgBox("No record found!")
      5.   End With
      6. End Sub
  2. Second Option
    1. Create an unbound ComboBox control on your form which lists all the records in the recordset (The same records that the form can select from - We'll call it cboSearch).
    2. In the After_Update event procedure have :
      Expand|Select|Wrap|Line Numbers
      1. Private Sub cboSearch_AfterUpdate()
      2.   Call Me.Recordset.FindFirst("[YourNameField]='" & Me.cboSearch & "'")
      3. End Sub
I don't know (or understand) why I would put a text box or a combo box on the form- what would they do?
What if I wanted to create a command button (I would call it "Search Records")
on the form that when clicked brings up a box to enter last name, then a box
to enter 1st name like a query?
Is that possible?
Jun 8 '07 #23

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

Similar topics

8
by: Olaf Meyer | last post by:
Sometimes if find it clumsy unsing the following approach building strings: cmd = "%s -start %s -end %s -dir %s" % (executable, startTime, endTime, directory) Especially if you have a lot of...
6
by: Sridhar R | last post by:
I am looking for a class browser that has these features. 1. Given a symbol (class, method or function) it should giveback the lineno n source code 2. It should be efficient and quick. I...
5
by: Manu | last post by:
Hi, Here's what i want to accomplish. I want to make a list of frequenctly occuring words in a group of files along with the no of occurances of each The brute force method will be to read the...
3
by: Jack | last post by:
Hi, I have a sql statement in asp page as below sql = " INSERT INTO tblExpense (ENO, EntryDate, ContractedServiceExpense, " sql = sql & "TravelExpense, PersonnelExpense)" sql = sql & "...
0
by: Rolan | last post by:
I'm using Access 97 and need some assistance in sorting out a proper DSum expression, or maybe even DCount might be an alternative. I have tried numerous combinations, but with no apparent success....
1
by: lhill | last post by:
Hello, I have a database in Access 2000. In my database I have a table that has 3 columns: ID, species and weight. I want to run a query that will count the number of species per ID and sum the...
1
by: Robert Neville | last post by:
Basically, I want to create a table in html, xml, or xslt; with any number of regular expressions; a script (Perl or Python) which reads each table row (regex and replacement); and performs the...
37
by: gardenfrogs | last post by:
I have fields in a table that include dates of meetings, phone calls, mailings, and other contact with clients. I have one field that is "most recent contact date". I want that default value to be...
2
by: Cirene | last post by:
My ASP.NET project builds fine (VS2008). I added a new web deployment project. When I try to build it I get: Data at the root level is invalid. Line1, position 1. (The file is web.config,...
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: 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
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.