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

How to create an expression that uses auto date with isnull

Breeves22
Hi I am fairly new to access and only just beginning to work with creating my own database.

I have three fields, the referral date, the visit date and the joint visit date.

I am trying to create an expression that will imput a date into the joint visit box based on whether the visit date box is filled in or not. For example if the referral box is filled in then but not the visit date then the joint visit box will come up with a date 30 days after the one in the referral box. but if the visit date box is filled in then the joint visit box will show a date ten days after the date in the visit box.

The code i have written is

Expand|Select|Wrap|Line Numbers
  1. =iif(isnull[Joint visit]), =DateSerial(Year([Referral]),Month([Referral]),Day([Referral])+30),=DateSerial(Year([Visit]),Month([Visit]),Day([Visit])+10))
  2.  
however i am not sure where i am going wrong so any help would be greatly appreciated.

Thankyou in advance
Sep 10 '10 #1

✓ answered by NeoPa

You would need some code similar to the following in your form's module, with both controls properly set to trigger the event procedures :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Referral_AfterUpdate()
  2.     With Me
  3.         If IsNull(.Visit) And IsDate(.Referral) Then _
  4.             .[Joint Visit] = DateAdd("d", 30, .Referral)
  5.     End With
  6. End Sub
  7.  
  8. Private Sub Visit_AfterUpdate()
  9.     With Me
  10.         If IsDate(.Visit) Then _
  11.             .[Joint Visit] = DateAdd("d", 10, .Visit)
  12.     End With
  13. End Sub

7 1805
TheSmileyCoder
2,322 Expert Mod 2GB
Its a bit hard to see where your using this bit of code, and also your don't mention what error you are getting.

Im gonna guess that you written it in the controlsource of a textbox, since you have a = at the front. Be aware that what you will get then is a DISPLAYED/CALCULATED value, and that value will not be stored anywhere.

Also if your textbox is called [Joint Visit] and you try to reference itself within its on controlsource, you will likely get errors as it becomes a circular reference.

Expand|Select|Wrap|Line Numbers
  1. =DateSerial(Year([Referral]),Month([Referral]),Day([Referral])+30)
  2. can be more smoothly written as:
  3. =DateAdd("d",30,[Referral])
What you can do is tie the filling of the field into a certain event, but you have to be clear on what the event should be. Should it be after updating a certain field? Or before saving the record?
Sep 10 '10 #2
Sorry the error message i am getting is you may have entered an operand without an operator.

And i entered it wrong on my entry. where the code says Joint Visit its meant to say visit date. i already corrected that problem
Sep 10 '10 #3
NeoPa
32,556 Expert Mod 16PB
Smiley raises a very fair point (See the bold text at the bottom of post #2).

I would guess you only want this value changed in certain, more specific, circumstances. Let me take a stab at guessing what you meant to say in the question and you can correct me if I'm wrong.

You have a form where you view/edit records which contain fields for the three dates named ([Referral], [Visit] & [Joint Visit]). Whenever the value in [Referral] is changed, but the value in [Visit] is still Null (empty), you want to set/update the value in [Joint Visit] to reflect a date 30 days after the date value in [Referral]. Whenever the value in [Visit] is changed, you want to set/update the value in [Joint Visit] to reflect a date 10 days after the date value in [Visit].

Can you please confirm or correct the accuracy of this for us before we proceed with suggesting a solution.

Welcome to Bytes!
Sep 10 '10 #4
Hi Neopa. Yes that is exactly what i am trying to do. Sorry for not making it clearer
Sep 13 '10 #5
NeoPa
32,556 Expert Mod 16PB
You would need some code similar to the following in your form's module, with both controls properly set to trigger the event procedures :

Expand|Select|Wrap|Line Numbers
  1. Private Sub Referral_AfterUpdate()
  2.     With Me
  3.         If IsNull(.Visit) And IsDate(.Referral) Then _
  4.             .[Joint Visit] = DateAdd("d", 30, .Referral)
  5.     End With
  6. End Sub
  7.  
  8. Private Sub Visit_AfterUpdate()
  9.     With Me
  10.         If IsDate(.Visit) Then _
  11.             .[Joint Visit] = DateAdd("d", 10, .Visit)
  12.     End With
  13. End Sub
Sep 13 '10 #6
Thats Fantastic works great now. cheers
Sep 14 '10 #7
NeoPa
32,556 Expert Mod 16PB
Very pleased to hear it :)
Sep 14 '10 #8

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

Similar topics

0
by: Liz Malcolm | last post by:
I have created a db for a non-profit, contacts, volunteers, donors, etc. Our statistical year ends on the last Sunday of September and starts on the first Monday following. Our statistical...
4
by: yer darn tootin | last post by:
Does anyone know the sort expression for a column that's data has been returned in the format, eg '07 Jul 05'?? The sort expression {..:"dd mmm yy"} doesn't work ( if the column was returned as...
1
Virtualmedia
by: Virtualmedia | last post by:
Hi I am writing a dynamic contact form for my website http://www.virtualmedia.co.nz (contactus.asp) everything works okay except that I want to insert an auto date function to record the date and...
2
by: S.Dickson | last post by:
I have a mysql table, with a field called DATE, how do i get it to automatilly put the date on it every time a new recored it put on the table Date and time would be good, Tahnks
4
by: ringer | last post by:
I have a db where each record is a certain task to be done. Each record includes the date the task should be completed. Some of the tasks are one time only but some are recurring. I have been having...
10
VietPP
by: VietPP | last post by:
Hi all, I'm using ComponentOne FlexGrid for VB.NET to display my data. To create a auto scrollbar using a timer object as: Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As...
2
by: heenakausar | last post by:
I want to create a drop down menu of month:, day:, and year. The difficulty with this one is that i dont know whether to make this a dynamic menu list - after all - the number of days within the day...
6
by: frys | last post by:
I have a form set up like a journal the top of the page has 2 fields dateID {autonumber) Date (date/time) under these there is a subform with ny notes section
0
brokensword008
by: brokensword008 | last post by:
Hello everyone. I'm new here. I have a problem with Expression Web. I have more than a hundred pages created from my self-made template. My website sells products so I subscribed to RomanCart for...
1
by: disney86 | last post by:
I am setting up Forms in Access 08. I have a form which when opened will auto insert the current time and current date. I need to be able to allow the user to set up paramaters to auto select a...
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:
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
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
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.