Locking Vaule in Form Field

cathalfarrell

Registered User.
Local time
Today, 14:11
Joined
Mar 10, 2008
Messages
41
Hi All

I am working on 'daily register' database.

I have a form where user presses a 'Start time' button and it updates the form with the current system time another button updates the finish time and the total hours for the day are displayed in a text box.

Is there anyway that I can stop the 'start time' button updating the start time after the initial entry has been made?

You help with this is much appreciated,

Cathal
 
just use the enabled property of the button if the control that holds the start time is already populated:
Code:
if not isnull(me.StartTimeControl) then
  me.StartButton.enabled=false
end if
similarly, you could use LEN():
Code:
if len(me.StartTimeControl) > 0 then
  me.StartButton.enabled=false
end if
This is probably best used on the current event of the form.
 
Doh!

Thank you for you quick response.

But I'm a but of a newbie and don't really know what to do with the code you have given me.

If you could advise me where place the code I would be very greatfull!

Thanking you in advance

Cathal
 
click on the form's property box in the upper left hand corner of the form in design view. click on the "event" tab. click the 3 "..." marks you see on the right hand side of the "On Current" line. copy and paste the code I gave you between the two lines that say "SUB" in them, but replace StartTimeControl and MyStartButton with the actual names of those controls on your form.
 
Thanks Adam

Agains Thank you for your help Adam,

I have done as you suggested however this doen't seem to work.

The button is no longer active at all, even on a new record with no value in the Start Time field.

Can you help?

Cathal
 
My Database

I have uploaded my database that someone might take a look at it and assist in preventing the updaing of the start time.

I have tried a few different combinations of code in the On_Current of the form but to no avail.

You help is much appreciated.

Cathal
 

Attachments

Last edited:
Cathal, I don't believe i can open the table with it being linked the way it is. Maybe try removing the link, and posting it again?
 
A couple of things -

1. For your start time button you have used the On Enter event. That event has nothing to do with the Enter key. It fires just as a control receives the focus, before the got focus event fires. What you want is the CLICK event for a command button.

2. This code you have in the form's current event:
Code:
Private Sub Form_Current()
If Len(Me.Start_Time & "") = 0 Then
   Me.AllowEdits = True
   Me.AllowAdditions = True
   Me.AllowDeletions = True
Else
   Me.AllowEdits = False
   Me.AllowDeletions = False
   Me.AllowAdditions = True
End If
End Sub

Will make it so you can never update the end time.

The corrected code:
Code:
Private Sub Form_Current()
If Len(Me.Start_Time & "") = 0 Then
   Me.StartTimeButton.Enabled = True
   Me.Start_Time.Enabled = True
   Me.Start_Time.Locked = False
Else
    Me.StartTimeButton.Enabled = False
    Me.Start_Time.Enabled = False
    Me.Start_Time.Locked = True
End If

If Len(Me.Finish_Time & "") = 0 Then
    Me.FinishTimeButton.Enabled = True
    Me.Finish_Time.Enabled = True
    Me.Finish_Time.Locked = False
Else
    Me.FinishTimeButton.Enabled = False
    Me.Finish_Time.Enabled = False
    Me.Finish_Time.Locked = True
End If
End Sub

Also, you really should be storing the date/time together for startdate/time and enddate/time as it will make your life much easier.
 
Thanks boblarson

This was exactly what I was looking for. Thank you for you explaination as to why the original code wasn't working, always nice to know where I'm going wrong for future application.

Also thanks to Adam for your assistance.

Cheers Guys
 

Users who are viewing this thread

Back
Top Bottom