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

Default date needs to earlier previous field + 1 day

Hi

I have a staff database to record absence.

I have a field in a table "Return notified" to display the date we were notified centrally staff returned to work (this could be some time after they actually came back - major management issue!!)

I want the default in this field to be the "last day absent" (an earlier field in the same table) + 1 day. Able to be typed over and ideally blank until we have a return date. It doesn’t seem to let me build this formula in the default box.

Can you help please?
Thanks in advance for your help
Jan 22 '10 #1
4 2117
TheSmileyCoder
2,322 Expert Mod 2GB
Lets pretend your textbox holding the first date is called tb_Date, and that after updating it, you want another text called tb_DateEnd to be filled in automatically.

Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_Date_AfterUpdate()
  2.   Me.tb_DateEnd=DateAdd("d",1,Me.tb_Date)
  3. End Sub
Jan 22 '10 #2
Thanks for this.

I want the field in the table to be completed so I am unsure of where to put the code?

Sorry I'm fairly new to access so still finding my way around it.

Thanks again
Jan 22 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Open your form in design view. As I understant it you fill in a date in this form in some field. Select that field, and open its properties (F4). Look for the property name, and name it tb_Date or whatever you find practical. Don't use spaces in control names.

Next click the tab "Event" and find the event called AfterUpdate. You should see a small box with 3 dots on the far right. Click the dots and select Event Procedure.

Your now in VBA mode, Visual Basic for Aplications. Might seem scary at first, but its actually not so hard.

If you named it tb_Date access will allready have added some code for you:
Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_Date_AfterUpdate() 
  2.   Me.tb_DateEnd=DateAdd("d",1,Me.tb_Date) 
  3. End Sub 
This is an event procedure, a small piece of code to be executed after the field tb_Date is updated, I.E. after you have entered the first date. Now we want it to do something.

Go back to your form, and select the field you want to be automatically filled in, and name it. In my example I just named tb_DateEnd. You can call controls almost anything, but its a good idea to not have spaces in it, and there are a few reserved words like "Date", which you should not use

Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_Date_AfterUpdate() 
  2.   Me.tb_DateEnd=DateAdd("d",1,Me.tb_Date) 
  3. End Sub 
This code says, after updating tb_Date, we want to perform some code. We want to set the field tb_DateEnd in the current form (Me is a reference to the current form) equal to something, so we call a built in function DateAdd. If you want information about DateAdd, just click on DateAdd and press F1. The first argument "d" tells the function we want to add DAYS (M for Months) to something. The 1 says how many of "d" we want to add, and finally Me.tb_Date is the variable we want to add something to.
The above code could also be written as:
Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_Date_AfterUpdate() 
  2.   Me.tb_DateEnd.Value=DateAdd("d",1,Me.tb_Date.Value) 
  3. End Sub 
However when Value is excluded Access defaults to assuming you wanted hte Value property.

If you have more questions feel free to ask (Possibly in a seperate thread)
Jan 22 '10 #4
NeoPa
32,556 Expert Mod 16PB
You talk about fields and the table, but do you possibly mean controls and a form that is built on the table?

Setting the default for a form control is much simpler, and what most people would be asking. Is that your question? Or do you really want to manage this at a field/table level?
Jan 25 '10 #5

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

Similar topics

3
by: Darren | last post by:
Hello, How would I write in SQL or ASP the following?: Count number of Database Records between NOW and 24 HOURS EARLIER? I know how to retrieve recordsets etc - its just the date thing I cant...
15
by: Paul J. Ettl | last post by:
Two questions: I use var date1 = new Date(); to get todays date. But how can I get yesterdays date? Furthermore I use
4
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them...
11
by: David Messner | last post by:
Ok I know this is simple but the statement eludes me... I have a date field where I want the default value on the data entry form's date field to be the last date entered. I figure I can do this...
3
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to same date. SELECT IM.Area, IM.Location,...
29
by: james | last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old database file that has the date(s) stored in it as number of days. An...
3
by: dpmcdoug | last post by:
I am a relative novice with Access and I am developing an input form that I need a default date to populate, regardless of the input date e.g. If I input data on Tuesday, Sept 27, I want the default...
1
by: Killer42 | last post by:
Hi all. I have a question from a colleague. He is creating a form in Word2003, which has a date field on it. He wants to set the default value to the current date, but allow the user to overwrite...
2
by: favor08 | last post by:
7/19/2007 12:46:30 am. is in a field called CmplteDte. It is a date stamp of when the user completed the item. I need the time for a report but for a form that the supervisors use to QA the previous...
1
osward
by: osward | last post by:
Hi everyone, Background 1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >=...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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.