Making one record read-only

  • Thread starter Thread starter evilcowstare via AccessMonster.com
  • Start date Start date
E

evilcowstare via AccessMonster.com

Hello,
I have a form which is used to input records into the main table, is there
anyway in which I could have a drop-down box or tick box which once selected
will lock that individual record?
For example if you are on record 24 and tick it it will make 24 read only
until the tick is unchecked?

Thank You
 
Add a Yes/No field to the table, and on the form bind a checkbox control to
that field. Then, in the Form_Current event, if the checkbox is checked lock
all controls on the form (or at least the ones you want locked). You can't
really lock the record in the table directly, you have to "lock" it at
runtime.

Carl Rapson
 
Hi Carl, thanks yet again for your help. Sounds like a god way to do it, just
let me get the code right for the Form_Current event...
I have named the checkbox "recordlock"
So the code im thinking of is..

recordlock.Enabled = Not IsNull(AddressCombo, Client Name, Address, etc etc)
Is this right or is there a better way to do it?

Thanks
Jay

Carl said:
Add a Yes/No field to the table, and on the form bind a checkbox control to
that field. Then, in the Form_Current event, if the checkbox is checked lock
all controls on the form (or at least the ones you want locked). You can't
really lock the record in the table directly, you have to "lock" it at
runtime.

Carl Rapson
Hello,
I have a form which is used to input records into the main table, is there
[quoted text clipped - 5 lines]
Thank You
 
'This will lock them when you move to a give record
Private Sub Form_Current()
If RecordLock Then
Me.AddressCombo.Locked = True
Me.ClientName.Locked = True
Else
Me.AddressCombo.Locked = False
Me.ClientName.Locked = False
End If
End Sub

'This will lock or unlock it immediately when you check or uncheck RecordLock
Private Sub RecordLock_Click()
If RecordLock Then
Me.AddressCombo.Locked = True
Me.ClientName.Locked = True
Else
Me.AddressCombo.Locked = False
Me.ClientName.Locked = False
End If
End Sub
AddressCombo

(AddressCombo, Client Name, Address, etc etc)
Hi Carl, thanks yet again for your help. Sounds like a god way to do it, just
let me get the code right for the Form_Current event...
I have named the checkbox "recordlock"
So the code im thinking of is..

recordlock.Enabled = Not IsNull(AddressCombo, Client Name, Address, etc etc)
Is this right or is there a better way to do it?

Thanks
Jay
Add a Yes/No field to the table, and on the form bind a checkbox control to
that field. Then, in the Form_Current event, if the checkbox is checked lock
[quoted text clipped - 9 lines]
 
Sorry, had this here as as reference!

DO NOT copy this (AddressCombo, Client Name, Address, etc etc)
'This will lock them when you move to a give record
Private Sub Form_Current()
If RecordLock Then
Me.AddressCombo.Locked = True
Me.ClientName.Locked = True
Else
Me.AddressCombo.Locked = False
Me.ClientName.Locked = False
End If
End Sub

'This will lock or unlock it immediately when you check or uncheck RecordLock
Private Sub RecordLock_Click()
If RecordLock Then
Me.AddressCombo.Locked = True
Me.ClientName.Locked = True
Else
Me.AddressCombo.Locked = False
Me.ClientName.Locked = False
End If
End Sub
AddressCombo

(AddressCombo, Client Name, Address, etc etc)
Hi Carl, thanks yet again for your help. Sounds like a god way to do it, just
let me get the code right for the Form_Current event...
[quoted text clipped - 12 lines]
 
Hi Thanks very much, ill give it a go tomorrow and let you know how it turns
out!!

Thanks Again!
Jay
Sorry, had this here as as reference!

DO NOT copy this (AddressCombo, Client Name, Address, etc etc)
'This will lock them when you move to a give record
Private Sub Form_Current()
[quoted text clipped - 26 lines]
 
Hi I just tried adding the code to the checkbox but it didnt do anything, I
tried it on one combobox but even after the record was saved it was still
allowing access to the combo-box.
Any Ideas?

'This will lock them when you move to a give record
Private Sub Form_Current()
If RecordLock Then
Me.AddressCombo.Locked = True
Me.ClientName.Locked = True
Else
Me.AddressCombo.Locked = False
Me.ClientName.Locked = False
End If
End Sub

'This will lock or unlock it immediately when you check or uncheck RecordLock
Private Sub RecordLock_Click()
If RecordLock Then
Me.AddressCombo.Locked = True
Me.ClientName.Locked = True
Else
Me.AddressCombo.Locked = False
Me.ClientName.Locked = False
End If
End Sub
AddressCombo

(AddressCombo, Client Name, Address, etc etc)
Hi Carl, thanks yet again for your help. Sounds like a god way to do it, just
let me get the code right for the Form_Current event...
[quoted text clipped - 12 lines]
 
It allows "access" to the combobox, i.e. the box drops down, but you'll find
that you cannot actuallu make a selection from the box! In other words, you
can't enter data using the combobox, which is what being "locked" means! the
only way to keep the combobox from from dropping down is to set the Enabled
Property to False.
 
Oh ok, sorry never actually used the lock function before.

Just so that I learn something else can you tell me what the different is
between putting the code in the actual button_on click and putting it in the
Form_on current.
I know that on click will refer directly to what happens when you click it. I
just dot understand what you meant by...

'This will lock them when you move to a give record ??

Should I have the code in both places? or can i just have it in the On_click?

Sorry if I am being thick, I am still learning and the only way to get better
is to ask when I have a query.

Thank You for your help!!!
With about 30 odd fields in my form guess im going to need to be using that
code a lot :o)

Jay
 
You absolutely HAVE to use both pieces of codes!

Private Sub RecordLock_Click()
If RecordLock Then
Me.AddressCombo.Locked = True
Me.ClientName.Locked = True
Else
Me.AddressCombo.Locked = False
Me.ClientName.Locked = False
End If
End Sub

This code locks the controls on the current record when the box is clicked.
If this was the only piece of code you used, once the the checkbox was
checked on ANY record, the controls on ALL records would be locked! Hence the
code you place in the Form_Current sub.

Private Sub Form_Current()
If RecordLock Then
Me.AddressCombo.Locked = True
Me.ClientName.Locked = True
Else
Me.AddressCombo.Locked = False
Me.ClientName.Locked = False
End If
End Sub

To repeat, if you lock the controls on Record # 1 say, then move to Record #
2, the controls on that record (and every other record) will also be locked.
Once a control is locked, it remains locked, for all records, until it's
unlocked! In order to only have the controls locked on records where the box
is checked, you have to determine the condition of the chekbox each time you
move to a new record. And that's what the Form_Current does! It checks the
condition of RecordLock. If RecordLock is checked, the controls on the
current record are locked. If RecordLock is not checked, the controls are not
locked.

Anytime you have to check a control on the current record before deciding
what to do with that record, such as locking control(s) or maybe highlighting
text in a control, or even making a control invisible the Form_Current event
is the place to do this.

Hope this gives you a little better understanding of how this works. And
don't apologize; the best way to learn is by reading, trying yourself, and
then asking questions when you have problems. That's why we're here! Oh, yeah,
and when you have a question about a particular command or function, place
the cursor in the middle of the word and press <F1>. Access Help will pop up,
and it's a great, but often overlooked, learning aid.

Good luck!

Linq

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
THANK YOU !!!!
I really appreciate it you explaining it in detail, Ive been using code here
and there but never really understood why it had to be repeated on a button
or check and the on current. Now I totally get it!!!
And yet again maked perfect sence.

Thank You loads and for the <F1> tip!!!
All the best
Jay
 
Hi Sorry, I have just noticed an error message and was wondering if you could
help me out with it.
The record lock works fine until I use the forms navigation buttons.
If i go to the last record I have and then click next record, it would
usually just say "cant go to specified record" but instead I am getting the
error message of....

Run-Time error '94':
Invalid use of Null

If I click Debug it highlights the line...

If recordlock Then

in yellow. This is the bit that is in the Form_Current area

I dont really know what it wants me do to :-/

Any Ideas?

Thank You !!!!!!!!!!!!!!!!!!!
 
Just a thought, I already have a lil bit of code I use directly above the
recordlock one, maybe it is trying to include it in the othe code.....


Private Sub Form_Current()
operativebutton.Enabled = Not IsNull(operativecombo)
sitebutton.Enabled = Not IsNull(AddressCombo)

If recordlock Then
Me.jobnumber.Locked = True
Me.datereceived.Locked = True
ETC
ETC
ETC

Should I put something between the AddressCombo part and the If recordlock
Then part???




Hi Sorry, I have just noticed an error message and was wondering if you could
help me out with it.
The record lock works fine until I use the forms navigation buttons.
If i go to the last record I have and then click next record, it would
usually just say "cant go to specified record" but instead I am getting the
error message of....

Run-Time error '94':
Invalid use of Null

If I click Debug it highlights the line...

If recordlock Then

in yellow. This is the bit that is in the Form_Current area

I dont really know what it wants me do to :-/

Any Ideas?

Thank You !!!!!!!!!!!!!!!!!!!
You absolutely HAVE to use both pieces of codes!
[quoted text clipped - 48 lines]
 
Add a Yes/No field to the table, and on the form bind a checkbox control to
that field. Then, in the Form_Current event, if the checkbox is checked lock
all controls on the form (or at least the ones you want locked). You can't
really lock the record in the table directly, you have to "lock" it at
runtime.

Michel 'Vanderghast' Walsh Access MVP once posted an interesting
approach to locking a record at the table level:

http://groups.google.com/group/microsoft.public.access.queries/msg/f70b1515e6bd9725

Jamie.

--
 

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

Back
Top