Full Version: DateDiff
UtterAccess Forums > Microsoft® Access > Access Forms
DonnaOAG
Okay - gave this my best shot but it's not working:
Private Sub Other_Work_Days_GotFocus()
Dim Other_Work_Days As Integer
[Other_Work_Days] = DateDiff(d, [Start_Date], [Other_Actual])
End Sub
Don't need to distinguish work days or anything - it's just a straight count of the days between a due date and an actual date.
Please help!
Thanks,
Donna
fkegley
I think it should be this:

Other_Work_Days = DateDiff("d", [Start_Date], [Other_Actual])

Edited by: fkegley on Wed Apr 26 20:59:26 EDT 2006.
Jack Cowley
Try putting double quotes around the 'd' in the function like below:
Other_Work_Days] = DateDiff("d", [Start_Date], [Other_Actual])
hth,
Jack
DonnaOAG
Hey Frank and Jack,
Tried both and while I don't get a code error now, nothing is happening / appearing in the [Other_Work_Days] field.
Jack - I think the last time I spoke to you over a year ago I was just about to graduate - never made the ceremony ... started festivities to early ;-)
Cheers,
Donna
Jack Cowley
Donna -
Try your code in the On Current event...
A year ago, huh? I barely remember yesterday so I am embarrassed to say that I don't recall your graduation but I am glad you didn't miss YOUR festivities!!! YEEHAAA!!!
Jack
GroverParkGeorge
Where is the field in which nothing appears? In a form I assume? What is the control source for that field? All your code actually does is calculate the value, but it then does nothing with it. if you want the control to actual display the calculated value, you need to assign it.

Private Sub Other_Work_Days_GotFocus()
Dim Other_Work_Days As Integer
Other_Work_Days = DateDiff("d", [Start_Date], [Other_Actual])
Me.txtOther_WOrk_Days = Other_Work_Days
End Sub



George
Edited by: GroverParkGeorge on Wed Apr 26 21:34:30 EDT 2006.
DonnaOAG
Hey Jack,
Unfortunately I did miss some of my festivities ... about the last five hours of them!
Are you saying I should use a macro?
Cheers,
Donna
DonnaOAG
Hey George,
The fields are on a form.
Cheers,
Donna
Jack Cowley
Donna -
There you having fun when you missed the festivities? If so then that is OK. If you were not then ya have to tough it out and move on to the NEXT festive opportunity!
I say NEVER use macros. Code is the ONLY way to go so trash any macros you have and jumb into code with both feet. Now that is a festive thought!
Jack
DonnaOAG
Hey George,
Tried that too. Getting the following error message - "Method or data member not found" -
on the line below:
Me.txtOther_Work_Days = Other_Work_Days
Cheers,
Donna
Jack Cowley
Donna -
I am not George, but try this code in the On Current event of your form:
If Not Me.NewRecord Then
Me.[txtOther_Work_Days] = DateDiff("d", Me.[Start_Date], Me.[Other_Actual])
End If
Let George and I know if this works. I assume that you have some data in your tables...
Jack
DonnaOAG
Hey Jack and George,
tried that last suggestion from Jack but again had a code error.
How about this instead:
I've made the control field =[Other_Actual]-[Start_Date], which calculates the days (joy!).
Now how do I get that number stored in my record / s?
Cheers,
Donna
Jack Cowley
Donna -
The answer to the question of how to store the difference is that you don't! You calculate it every time, just as you are doing now... In Access you save calculations VERY VERY rarely because you can calculate them 'on the fly' whenever you need them.
I am glad to hear you have found a solution! Not sure why the other code did not work, but without seeing your db it is hard to pinpoint the reason it wasn't working...
Now the sun is well past the yardarm so I am off to the wine cellar for little taste of the grape.. It has been nice chatting with you and I see some festivities in your near future!!!
Jack
DonnaOAG
S'funny - you had a yardarm last year too. Are you finding your's getting earlier and earlier?
uchos gracias.
Donna
Jack Cowley
Donna -
OL! Yes, the yard arm is coming around earlier and earlier! I did not want to mention it, but I did make my trip to the wine cellar 'a while back'...
De nada y enga un resto agradable de su día... Or something close to that....
Jack
PS. You don't say where you are in this wild world but 'Cheers' is a clue that is confounded by your Spanish... No es importante....
DonnaOAG
¿Qué puedo decirle? Soy una mujer de muchos talentos. ¡Bonito perdido mucho en Nueva Zelandia!
GroverParkGeorge
Me alegra que Jack te ayudo.
Osobrino y su esposa regresaron de Nueva Zelandia hace un mes. Disfrutaron muchos de este pais tan lindo y me dijeron que se encontraron con el unico Venezolano en todo el pais. Se conceiron por la franela con nombres de sitios Venezolanos, o algo asi, caminando por una playa.
The solution I would recommend would be to use the DateDiff function instead of the math calculation for the control source.
=DateDiff("d", [Start_Date], [Other_Actual])
George
Jack Cowley
Ah ah! I was right in my thinking as to where you live! Hooray for me for remembering something!! And you certaily are VERY talented.... Big sigh...
ack
Jack Cowley
My oh my oh my... Author. Linguist. Man about town. Access genius. Un que companero asombroso usted es George...
ack
DonnaOAG
Hey Jack and George,
Thanks for all your help. What's this about george's kin visiting New Zealand and something about Venezuela or volcanoes?
¡Ninguna duda estaré detrás!
Au revoir,
Donna
Jack Cowley
Donna In NZ -
haven't a clue about all for George's atributes or his kin, but he is one clever fellow! And I have used up all my Spanish vocabulary....
Otrust all is well in NZ....
Jack
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.