PhilipEwen
06-11-2001, 09:52 AM
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
06-11-2001, 10:04 AM
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
06-11-2001, 10:09 AM
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
06-11-2001, 10:13 AM
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
06-11-2001, 10:20 AM
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
06-12-2001, 07:37 AM
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
06-12-2001, 09:59 AM
WOW ! Thanks you so much for your help.
Very appreciated