locking records

  • Thread starter Thread starter fishqqq
  • Start date Start date
F

fishqqq

I'm using Access 2000 and i would like to know if there is a way i
could put a check box on a form which when the user checks the box
would lock all the fields in on that form. (so the user couldn't alter
any of the fields any longer?

how would i do this???

any better suggestions on how to lock fields in a form would be greatly
appreciated.

Tks
Steve
 
Hello Fishqqq -

I would just disable all of the fields. I don't know exactly what type of
fields you have, but if you have a textboxes, for example, txtName,
txtAddress, you could do something like
txtName.Enabled = False
txtAddress.Enabled = False

HTH
 
Locked=True would be a more accurate implementation of what she has
asked, rather than Enabled=False. Locked & Enabled have somewhat
different effects (as you probably know already).

HTH,
TC
 
I'm using Access 2000 and i would like to know if there is a way i
could put a check box on a form which when the user checks the box
would lock all the fields in on that form. (so the user couldn't alter
any of the fields any longer?

how would i do this???

any better suggestions on how to lock fields in a form would be greatly
appreciated.

Tks
Steve

This kind of locking isn't very easy, and a determined and
knowledgable user can get around most any scheme you can devise. The
question is - are you trying to make it unlikely that a user will
unintentionally edit data they shouldn't? or the much more difficult
task of protecting your data from someone who's TRYING to do so, rules
be damned?

For the former, you can put code in the checkbox's AfterUpdate event,
and *also* in the form's Current event:

Me.AllowUpdates = Not Me!checkboxfield

This will allow updates on the form only if the checkboxfield is
FALSE. It won't, of course, stop the user from opening the table
directly, or running an update query - you'll need to implement Access
security to do that.

John W. Vinson[MVP]
 
Setting the status for the whole form is easiest - but often you will
want to allow some textboxes to be editable while locking the rest (at
least, I often do) ...

I use the Tag property to 'flag' those fields I don't want to lock. I
lock all other 'suitable' fields.

Dim ctl As Control
For Each ctl In Me
If ctl.Tag = "Edit" Then ctl.Locked = False
Next

is the kind of thing that you could use. You could, of course, do it
the other way around and only lock certain fields.

The code needs to be in the On Current event and in the After Update
event of your checkbox.

Should be enough to give you the idea.

HTH

Jeff Bailey
 
Hi John,
i have a little understanding of what you are suggesting... i added a
field to my table "lock" & a check box to my form "lock" (which has
subforms in it which also need to be locked btw) and i'm getting an
error.

please show me what i'm doing wrong.

Private Sub lock_AfterUpdate()
Me.allowUpdates = Not Me!checkboxfield
End Sub


tks steve
 
THis could be the problem my form has a subform in it too. i need the
fields in both the main form and subform to lock with i check the
checkbox. is this possible?
 
the error i get is "Compile error - method or data member not found"

This suggests that your code is using a name for a Form or Control
which does not match any existing form or control.

Please remember - You can see your code and your form. We cannot.

Please post the actual VBA code that is generating the error, and also
post the Name properties of the Form, the Subform control, and the
control(s) on the form which you are trying to lock. Give us a bit of
help so we can help you!

John W. Vinson[MVP]
 
Tks John, i know some people are touchy about having code pasted in the
newsgroups...

the Mainform is called: profit tracking 2
and it has a subform called: Profit Tracking (Receivables) and another
subform called: Profit Tracking (Costs)

The idea is the user puts in all the AR and AP information and once
completed the user will lock the record himself (which will send the
data to the accounting dept). This will turn the form into readonly ...
(I was going to lock it by having a command button's 'click' event to
set the checkbox to -1). Later if the user wishes to change the data he
can't. that's the way it's supposed to work.

I put the check box in the "detail" section of the main form.

The code is as follows.

(code pasted in the forms Current event)
Private Sub Form_Current()
Me.AllowUpdates = Not Me!checkboxfield
End Sub

(code pasted in the checkbox's after update event)
Private Sub Check75_AfterUpdate()
Me.AllowUpdates = Not Me!checkboxfield
End Sub


Tks again for your assistance.
 
I just noticed you asked for the name of the controls on the
forms/subforms which i want to lock. THere are many fields in these
forms. Do you need me to list all of them? (approx +30).
 

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

Similar Threads


Back
Top