Locking records?

R

Rolf Rosenquist

Having tried to lock records for editing by scrolling, but cannot get it
working.

When the user scrolls back to old records, I want to have them locked to
prevent editing.
I have tried to find an event for the form for that to happen, but without
luck.
I could only lock them or unlock them But then it also affected the normal
input. So that does not work.

Does anyone know how that would be possible?
/ Rolf
 
B

Brian Bastl

Rolf,

open the form in design view, and bring up its property sheet. Set 'Allow
Edit' to No, 'Allow Additions' to Yes.

HTH,
Brian
 
R

Rolf Rosenquist

But that is only possible when I do it for myself. I want to lock the inputs
when the user scrolls from a new blank record to the old ones. And when that
happens I can set the property of the fields to be able to edit or not with
VBA code.

But my problem is that I cannot find an event that tells the code when the
user go from a blank post to an old one.
Can you or somebody help me with this event, I would be very greatful.

/ Rolf
 
B

Brian Bastl

I'm not quite understanding 'when I do it myself'.

Perhaps you are looking for the form's Current property. It fires whenever
you navigate to a record.

Something like the following:

Private Sub Form_Current()
Me.AllowEdits = Me.NewRecord
End Sub

But setting the form's Allow Edits on the property sheet will do exactly the
same thing.

Brian
 
R

Rolf Rosenquist

Brian

Yes, I think we come closer to what I want. But to my understanding the
Form_Current fires both when I scroll to an old record as when I am writing
a new one. If I set the Allow to false then no new records can be input.
How to discern between those two different events?

/ Rolf

P.S With 'when I do it myself' I mean that I, who design the form, can
easily change what I want on the records. But I do not want to let the user
change them. By mistake or intentionally. These records must stay as they
are input from the beginning.
 
R

Rolf Rosenquist

Sorry Brian

I did answer too soon. I see afterwards that your suggestion seems to work
perfectly!

Then I have a date field that sometimes should be updated and sometimes not.
And that interfeers with what we now have done. But it is another problem
that I have to deal with. If I get stucked, perhaps I come back here.

Many thanks for your help. I'm happy to have learned one step further with
your support!

/ Rolf
 
B

Brian Bastl

Rolf,

1. you are correct about when the Current event fires.

2. by setting 'Allow Edits' to No and 'Allow Additions' to Yes on the
property sheet, you are allowing the form to accept new records without
allowing the user to over-write existing records.

3. The 'Me.AllowEdits = Me.NewRecord' does exactly the same thing as the
above. It essentially states that edits are allowed only if you are on a new
record; otherwise, edits are not allowed.

Probably the best way to test this is to create a form, setting its
properties like I stated originally. Try it out. Then go back to the
property sheet, and set 'Allow Edits' to Yes, and then add the code I gave
you to the form's Current event. Try that out. You'll see that they
accomplish the same thing.

HTH,
Brian
 

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