473,770 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to set a date field to autofill based on a another date field

25 New Member
Hello,

I am trying to get a date field to autofill based on the date of another date field. I want the autofilled date to be 30 days after the other date. For example, if the user has entered 06/15 in the first date field, I want the second field to automatically populate with 7/15. I have tried everything I can think of to no avail! I can't imagine this is a difficult thing to do........

Anyone have any ideas?
Jan 14 '10 #1
12 15986
ADezii
8,834 Recognized Expert Expert
Assuming your 2 Date Fields are [Date1] and [Date2], in the AfterUpdate() Event of [Date1], place the following code. When finished, it should look like:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Date1_AfterUpdate()
  2.   'Is there a Value in [Date1] AND is it a Valid Date?
  3.   If Not IsNull(Me![Date1]) And IsDate(Me![Date1]) Then
  4.     Me![Date2] = DateAdd("d", 30, Me![Date1])
  5.   End If
  6. End Sub
Jan 14 '10 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
In the after update event of datefield1 put the following code ...

Expand|Select|Wrap|Line Numbers
  1. Me!datefield2 = DateAdd("d", 30, Me!datefield1)
Jan 14 '10 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
LOL! Snap
Jan 14 '10 #4
klbrownie
25 New Member
Thanks ADezii!

I was trying something close to that, but apparently ooooh soooo far off!!! :)
Jan 14 '10 #5
NeoPa
32,573 Recognized Expert Moderator MVP
The answer depends on how you intend to use this field to my mind. If you're entering new data then it's probably better to set the .DelaultValue property of the control. If it's simply for display, then set the .ControlSource to :
Expand|Select|Wrap|Line Numbers
  1. =IIf([DateField1] Is Null,Null,DateAdd('d',30,[DateField1]))
Jan 14 '10 #6
klbrownie
25 New Member
@NeoPa
NeoPA, I see what you were talking about now. The date field is populating on the form, but it not in the table. How do get the date into the table as well?
May 11 '10 #7
missinglinq
3,532 Recognized Expert Specialist
You don't! Very seldom is there a valid reason to store a calculated value in a table! It wastes storage space, and running a calculation is almost sure to take less time than retrieving a value form the disk.

Instead, you merely re-calculate the value as needed, in a form, report or query.

Welcome to Bytes!

Linq ;0)>
May 11 '10 #8
NeoPa
32,573 Recognized Expert Moderator MVP
What he just said :)
May 11 '10 #9
davidmacias
1 New Member
Not sure if this will help but I had a similar issue and this is what I did....

ACTION DESIRED: Have one date field trigger (calculate) future or past date values in other date fields in a form and (Most importantly)hav e those values save in the master database table and queries.

TRIGGER FIELD: Re Insp Date

AFFECTED CALCULATED FIELDS: Re Insp Date 90 Day (To be set to -90 from "Re Insp Date") Re Insp Date 60 Day (To be set to -60 from "Re Insp Date") Re Insp Date 30 Day (To be set to -30 from "Re Insp Date")

SOLUTION: Opened up the properties of what is to be the "trigger" date field went to 'All' tab Opened up a 'Code Builder' Event Procedure in the "After Update" property Entered the following VBA code

Expand|Select|Wrap|Line Numbers
  1.    Private Sub Re_Insp_Date_AfterUpdate()
  2.    Re_Insp_Date_90_Day = Re_Insp_Date - 90
  3.    Re_Insp_Date_60_Day = Re_Insp_Date - 60
  4.    Re_Insp_Date_30_Day = Re_Insp_Date - 30
  5.  
  6.    End Sub
NOTE: If there are spaces in the name fields, an underscore has to replace the spaces. As shown in the VBA code above, "Re Insp Date" field name must be coded as "Re_Insp_Da te". (This is why many suggest you use no spacing in when naming database fields, tables, queries, forms, objects, etc)

Hopefully this helps someone else in the future.

Anyway, there it is.
May 20 '15 #10

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

Similar topics

0
3475
by: Chris Sharman | last post by:
I'd like to design my pages to work cooperatively with browser autofill features. I've loked around, but can't find any good documentation on supported/unsupported field names (http://toolbar.google.com/autofill_help.html gives some details, but doesn't make it clear to me how to name my form fields; rfc3106 only seems to cover ecommerce specific data). I'd like a delivery name & address (primary); a contact name & address (if...
0
2300
by: Ray Holtz | last post by:
Is it possible to autofill a field based on what is entered into another field in a form? My form has an employee field, and department field. In an Items Table, I have fields FldEmployee, and FldDepartment. FldEmployee is looked up from an TblEmployee Table which also has fields FldEmployee and FldDepartment. This FldDepartment field is looked up from a TblDepartment table that just has FldDepartments. I hope I explained that OK The...
2
1749
by: Edwin Knoppert | last post by:
I would like to instruct a grid which autofill's the columns to exclude time or date from a date field when date or time is 0. Date and time can be stored in a date field, my grid shows for example: 30-12-1899 13:23:12 Or: 15-11-2005 0:00:00
1
4266
by: Stephen D Cook | last post by:
I have a search form with a query-linked subform. One of the fields in the subform are date fields. Is there a way to autopopulate the DateFilled field when the person enters the field? I need this to be code which is entered into the form, rather than as a property of the field in the table because there is other data which is entered before. This data is entered in at a later date.
10
2852
by: sandraz444 | last post by:
I have an expression in the query under my form to autofill the date under a certain condition but it wont write to the underlying table?? The date shows in the form but not the table. Does anyone know a solution for this? Thanks!
2
2565
by: dympna | last post by:
Hi can anyone suggest a fix for this... as I am a novice in access. I have created a training table with the following fields Employee Name - joe Training Received - Fork lift Date Received - 20/6/07 Certificate - yes What I want to create is a renewal date for this training, there are
0
2057
by: Randy | last post by:
Hi, I have some comboboxes that are created dynamically at run time based on user actions. I found a procedure on a message board to autofill the combobox text from the dataview that the comboboxes are bound to. It works perfectly on the comboboxes that I have created at design time, but the ones that I create runtime behave differently. The problem is that when the user tabs onto the combobox, the box stays blank, which is fine. ...
3
1455
by: newyorkcity | last post by:
I have two fields in a form: Client ID Client Name I wan to be able to enter the Client ID and have the name of that client to appear automatically under the client name field. How do I do this? Thank you
8
5391
by: mjvm | last post by:
Hi, I'm new to asking for help on the web, but haven't been able to find an answer to my question through Google - probably because I am not using the right words. In my form, I want to be able to make an entry in the 'worker' field, and then on a mouse click, it automatically puts today's date in the 'Date allocated' field. I have tried to build an event through expression builder, but that didn't work. I thought if i made the event on...
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.