473,386 Members | 1,883 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.

Control source for Expiration date

Hi,
I am trying to modify a database that has a form with chemicals,manufacturing date and expiration date. They want the expiration date to be automatic so I used Dateadd in the field. However, in the report, I have no idea how to set the coding like if they ask for a chemical with 2 years expiration, that will show. I can provide additonal info if needed.
Thanks in advance!
Sep 27 '12 #1

✓ answered by zmbd

Ok,
You can start hard-coding these chemicals in a bunch of switch conditions or IIF functions on the report which means you'll have to maintain this for every product name change (or if you're lucky, just when product ids need to be added, deleted, modified, etc...)

and

someone like myself that inherits these "broken" databases will "Bless" you greatly in the future...

OR

You need to back to the data tables and look at where the expiration information is stored, if at all. If it is already stored... HURRAY, you can use that information in your calculated form!

IF not... then you either need to add a table (yuck) or add a single field to the product table storing the expiration... I'd use months... for the compounds. Once done, then use this information in the control.

8 3701
TheSmileyCoder
2,322 Expert Mod 2GB
Assuming you have written the chemicals expiration date in a field dt_Expiration you could query it like so:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl_Chemicals WHERE dt_Expiration is between Date() and DateAdd("yyyy",2,Date())
Sep 27 '12 #2
zmbd
5,501 Expert Mod 4TB
Hello and Welcome

Provided you haven't stored the information in a table already....

In a report you'd set the record source of an ubound control to the calculation: =Nz(DateAdd('yyyy',6,[manfdate]),"Missing ManfDate!") this adds 6 years to the date shown in the bound control [manfdate] or returns a the mesage. You can also use the IIF or SWITCH branchs too.

I typically do this in the query doing the same thing in a calculated field except I return an error, thus if the expiry is different (6mo for one, 1yr for another etc) for each product I can use the information from the table.
Sep 27 '12 #3
Thanks for the replies. I think I need to provide more information.
The report is actually a certificate of analysis wherein it extracts chemical from form and the expiration date is dependent on the type of chemical. We only have 2 expiration. One is after 6 months and the other is after 2years. The database was really complex and as much as possible I want to resolve this using an unbound field in a report. I tried doing IIf but somehow I just cant make it work. I'll post the IIf statement that I did.
Sep 28 '12 #4
I put this in the control source of the field named "Expiration" on the rpt:

Expand|Select|Wrap|Line Numbers
  1. =IIf([ProductName]="T-8 Conc.","DateAdd("m",6,[Date])","DateAdd("yyyy",2,[Date]"))
T-8 Conc. is one of the chemical with 6 months expiration.There are only 3 chemicals with this expiration and the rest are all 2 years. Thanks for any input.
Sep 28 '12 #5
zmbd
5,501 Expert Mod 4TB
Ok,
You can start hard-coding these chemicals in a bunch of switch conditions or IIF functions on the report which means you'll have to maintain this for every product name change (or if you're lucky, just when product ids need to be added, deleted, modified, etc...)

and

someone like myself that inherits these "broken" databases will "Bless" you greatly in the future...

OR

You need to back to the data tables and look at where the expiration information is stored, if at all. If it is already stored... HURRAY, you can use that information in your calculated form!

IF not... then you either need to add a table (yuck) or add a single field to the product table storing the expiration... I'd use months... for the compounds. Once done, then use this information in the control.
Sep 28 '12 #6
Hi ZMdb,

Thanks a lot! Somehow I was able to get the IIf statement working. So happy I don't need to edit any macros or add any tables or queries.
Sep 28 '12 #7
zmbd
5,501 Expert Mod 4TB
I'm glad that you've got this to work...

Two things...
The IIF is (IMHO) not the best long term solution. You'll run into the issue soon enough.

Second... [Date]
I highly advise you to change this field name.
"Date" is a reserved word in VBA/SQL and it will eventually cause you issues.
I've never figured out why the table designer doesn't simply disallow the reserved word usage instead of relying on the user to get this information from the help files, classes, or other programmers.
Sep 28 '12 #8
Thanks for the feedback. I foresee I'll have problems soon but since this is a bit urgent, we'll use this first and I'll think of how I can modify some of the field names. I really have issue with that [Date].
Thanks again ;)
Sep 29 '12 #9

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

Similar topics

2
by: Christophe Lance | last post by:
Hello, I use PHP session cookie to store an id number. I know how to set a cookie expiration date using the setcookie function, but how to set an expiration date when the cookie is created by...
0
by: Rock | last post by:
Hi,all: I have find a example to set expiration date of word permission object, but it was using VBA code. Dim objUserPerm As Office.UserPermission Set objUserPerm =...
2
by: Frederic Gignac | last post by:
Hiya all, My buddy and I got a bug with the expiration date of a cookie. When we want to look out the expiration date, the only thing we've got, it's 01/01/0001. As we know, when we want to...
0
by: Diffident | last post by:
Hello All, I cached a string object into Cache and set absolute expiration date. Now, I would like to retrieve the absolute expiration date of that object. Any API's available? Any pointers?...
10
by: Mike9900 | last post by:
Hello, I would like to store application expiration date in a file and store that file in a secure place, so the application can access the file for all the users on that computer. ...
1
by: phillip.s.powell | last post by:
I have a table, "article" that has a datetime field "article_expires". In my SQL statement I have this: SELECT id, title, body FROM article WHERE (article_expires IS NOT NULL OR...
1
by: rinmanb70 | last post by:
For a field on a report, I'm trying to use an If/Then statement to set the Control Source depending on the day of the month. I need one Control Source for days 1-14 and another for 15-31. To do...
4
by: Anja | last post by:
Hi everyone, I am trying to use the expression builder to create input to a control in an Access report. I have a table called Records and I want to select the minimum date for a record where...
3
by: dave | last post by:
I need to compute an expiration date based on the number of hours, days, or months purchased. The expiration date needs to be expressed in minutes something like '1260481600'. How can I get the...
2
by: Steve Covert | last post by:
Does anybody have any clever technique to implement an expiration date in a WinForms app, such that it could outsmart any user who tries to change the system clock to avoid expiration?
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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,...

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.