Locking / Unlocking entry in forms (1 Viewer)

PhilipEwen

Registered User.
Local time
Today, 09:26
Joined
Jun 11, 2001
Messages
81
Hi,
I am using a an unbound text box in a form to enter criteria for a query. The query reports back to the form the found data ( using the ( Me.Requery command on the 'search' button ).
What i want is to make this data so it cannot be edited by mistake. Then have a button on the form named 'edit' which unlock the form or even opens another similar form, finds the record and then allows editing.
Which is the best way, and how do i do it

Any help is greatly appreciated.
 

jatfill

Registered User.
Local time
Today, 04:26
Joined
Jun 4, 2001
Messages
150
the way I would do it is after the "requery" function, add an expression that sets the unbound text box control Enabled property to "no." Then all you have to do is make an edit button that performs the opposite function (sets the enabled property to yes). I dont' know the VB code, but it looks something like

Forms![FormName].[ControlName].[Enabled]
 

PhilipEwen

Registered User.
Local time
Today, 09:26
Joined
Jun 11, 2001
Messages
81
Thanks for your prompt reply.
If you set the enabled to no, then all the info becomes greyed out. That's why i just wanted to lock it to prevent editing, then perform a 'magic' unlock command, similar to how you describe.
Do you know how this would be done ???
 

jatfill

Registered User.
Local time
Today, 04:26
Joined
Jun 4, 2001
Messages
150
same exact process, just change the reference to

Forms![FormName]![ControlName].[Locked]

I use the Enabled because it gives the end user more of a visual cue that they can't do anything to the record... but either one will work pretty much to the same effect: you can't edit the control. :)
 

PhilipEwen

Registered User.
Local time
Today, 09:26
Joined
Jun 11, 2001
Messages
81
Thanks for your help.
Unfortunately i am lost on the VB code and havn't got a clue. I understand the principle though, so it was very helpful.

Thanks again.
 

Angello Pimental

Registered User.
Local time
Today, 09:26
Joined
May 9, 2001
Messages
92
Try this out:

1. Create a command button, with the following parameters:

Name: editlock
Caption: UNLOCK RECORD
On_click: Paste the code seen below

Private Sub editlock_Click()

Dim frmMyForm As Form
Dim ctlMyCtls As Control
Set frmMyForm = Forms!Nameofyourform

If editlock.Caption = "UNLOCK RECORD" Then
For Each ctlMyCtls In frmMyForm.Controls
If ctlMyCtls.Tag = "unlockme" Then
ctlMyCtls.Visible = True
ctlMyCtls.Enabled = True
ctlMyCtls.Locked = False
editlock.Caption = "LOCK RECORD"
Me.Refresh
End If
Next ctlMyCtls
Else
For Each ctlMyCtls In frmMyForm.Controls
If ctlMyCtls.Tag = "unlockme" Then
ctlMyCtls.Enabled = False
ctlMyCtls.Locked = True
editlock.Caption = "UNLOCK RECORD"
Me.Refresh
End If
Next ctlMyCtls

End If

**Note: Replace nameofyourform with the name of your form***

2. Now for every item on your form that you wish to be able to unlock, then lock do the following:

Enabled = No
Locked = Yes
Tag = unlockme

That should do it, if you have any questions just ask.

HTH

Angelo

[This message has been edited by Angello Pimental (edited 06-12-2001).]
 

PhilipEwen

Registered User.
Local time
Today, 09:26
Joined
Jun 11, 2001
Messages
81
WOW ! Thanks you so much for your help.
Very appreciated
 

Users who are viewing this thread

Top Bottom