automatically update time

cc.caroline15

Registered User.
Local time
Today, 04:59
Joined
Oct 23, 2014
Messages
23
Hi everyone I'm new to programming and MS access
I have a form fmrClasses and what I'm trying to do is write a code that as soon as the user types a beginning time will update the end time to 3 hours later for example If user enters 9:00AM for beginning time the end time will be set to 12:00 pm. Please Help me..Thank you!
 

Attachments

Last edited:
Hi CJ_London,
I tried it with an after update event but didn't work can you please help me more??
 

Attachments

  • Capture.PNG
    Capture.PNG
    4.6 KB · Views: 89
you can do one of two things

1. if your fldEndTime is bound, put that code into your fieldStartTime after update event

2. if it is not bound (i.e. the controlsource is blank) then you would put the following in your controlsource for fldendtime

=dateadd("h",3,nz([fldStartTime]))

This latter would produce an error if fldstarttime is blank (it will clear once a value has been entered) so I've added the nz function so a 3 is shown for now. This may or may not suit your requirements but will need to know more to offer alternatives
 
Hi CJ_London,
I tried using both if your suggestions and the first one did work but I still need to do something else.. here is what I was told to do:

  • On the Classes form, if the user enters a time in the Start Time field, set the value of End Time to 3 hours later (Hint: fldEndTime.Value = Format((TimeValue(fldStartTime) + (3 / 24)), "hh:mm AMPM"))and move the cursor to the Instructor field.
I tried using the hint formula with the after update event but it didn't work, do you have any other suggestions how to accomplish this?? Thank you
you can do one of two things

1. if your fldEndTime is bound, put that code into your fieldStartTime after update event

2. if it is not bound (i.e. the controlsource is blank) then you would put the following in your controlsource for fldendtime

=dateadd("h",3,nz([fldStartTime]))

This latter would produce an error if fldstarttime is blank (it will clear once a value has been entered) so I've added the nz function so a 3 is shown for now. This may or may not suit your requirements but will need to know more to offer alternatives
 
do you have any other suggestions how to accomplish this
What is 'this'? The hint does exactly the same as I advised but in a different way but also formats the value - the bit in red is the equivalent to my suggestion, the bit in black the formatting

Format((TimeValue(fldStartTime) + (3 / 24)), "hh:mm AMPM"))

The hint is the answer in this respect, so there is no reason why it shouldn't work. Also 'but it didn't work' is not helpful to help explain why it didn't work - there will have been an error or result of some sort which you need to explain what it is and why it is 'wrong'

Perhaps your tutor is trying to get you to learn about formatting so another way this can be achieved is by formatting the control rather than the value and the hint is telling you what the format string is required to be to use in the control.

The move to the instructor field is

instructor.gotfocus
 
Hi,
I tried the hint with the after update event on the end time field and after I change the start time it doesn't automatically change the end time. Before I add the get focus part of the code it does change It but on the start time field but when I add it it doesn't do it anything.
What is 'this'? The hint does exactly the same as I advised but in a different way but also formats the value - the bit in red is the equivalent to my suggestion, the bit in black the formatting

Format((TimeValue(fldStartTime) + (3 / 24)), "hh:mm AMPM"))

The hint is the answer in this respect, so there is no reason why it shouldn't work. Also 'but it didn't work' is not helpful to help explain why it didn't work - there will have been an error or result of some sort which you need to explain what it is and why it is 'wrong'

Perhaps your tutor is trying to get you to learn about formatting so another way this can be achieved is by formatting the control rather than the value and the hint is telling you what the format string is required to be to use in the control.

The move to the instructor field is

instructor.gotfocus
 
tried the hint with the after update event on the end time field
It should be in the afterupdate of the starttime control as previously advised
 
Thank you! it's working now, I didn't quite got what you were saying at first but now I do! Thanks again!
 

Users who are viewing this thread

Back
Top Bottom