Lock two fields?

K

Keith

I have a form, that a couple people use. Can I take the below and lock two
fields instead of 1? The two fields would not always have data in them at the
same time. One person opens the form, does their work, then another person
does their work and closes it, I want to be able to lock those fields so the
next time it opens those two fields are locked.

Would I just duplicate the same code and have 2 on current events?

Private Sub Form_Current()
If Not IsNull(Me.DueDate) Then
DueDate.Locked = True
Else
DueDate.Locked = False
End If
End Sub
 
L

Linq Adams via AccessMonster.com

NO! You can only have one of any given event in a form! Just put both sets of
code in your On Current event.

Private Sub Form_Current()
If Not IsNull(Me.DueDate) Then
DueDate.Locked = True
Else
DueDate.Locked = False
End If

If Not IsNull(Me.OtherField) Then
OtherField.Locked = True
Else
OtherField.Locked = False
End If
End Sub
 
B

Beetle

You can lock as many controls as you want in an event;

Private Sub Form_Current()
If Not IsNull(Me.DueDate) Then
DueDate.Locked = True
Contol2.Locked = True
Else
DueDate.Locked = False
Control2.Locked = False
End If
End Sub

You just need to make sure you have some method by which to unlock them
if they ever need to be edited
 
K

Keith

I guess what I need is:
I have 2 checkboxes that time stamp a field. One group opens the form, does
their work and then closes it. Then another group has their own checkbox that
timestamps. So, can I lock the timestamps after each group?
Does this make sense?

Thanks,
Keith
 
B

Beetle

So you have two text boxes, each of which is time stamped
programmatically when the check box is clicked? If that is the
case then you can just set the text boxes to locked = Yes in the
properties (no code needed). Having a control locked does not
prevent you from changing it's value via code

Or do the users have to manually enter the time?
 
B

Beetle

I just reread your post and realized I may have misunderstood you. Are
you only timestamping the underlying field in the table (no text boxes
that display the timestamp value on the form)?

And are you trying to prevent the value from being overwritten if
the checkbox is clicked again?
 
K

Keith

Yes, when they check the checkbox it time stamps a field.
Then another group goes in and checks their box and it time stamps another
field.
So, two groups will open the same form, after each group closes it, I want
to lock that groups field. Hopefully that makes more sense.
 
K

Keith

Yes, the text boxes (timestamps) are displayed but are locked.

Yes, that is exactly what I'm trying to do. I don't want the value
(timestamp) to be overwritten once it's clicked or they exit the form and go
back in.

Thank you for all your help,
Keith
 
B

Beetle

Here is one example of code that could be used in the After Update
event of the checkbox;

Private Sub checkbox_AfterUpdate

If Me.checkbox = True Then
If IsNull(Me.DueDate) Then
Me.DueDate = DateAdd("d", 30, Date())
End If
End If

End Sub

The above code would set the due date to 30 days from today.

First, this code would only run if the checkbox was being changed
from False to True (unchecked to checked) otherwise it would do nothing.

Second, the code would only run if the Due Date was null. If there was
already a value there, it would do nothing.

As long as the text boxes were locked (which I would do in the properties
for each text box), then the time stamp could not be overwritten (at least
not without doing it directly in the table)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top