Read-only, protect a form...

This is what I have entered under 'on click' on my check box. I have right clicked it under 'design view' and clicked 'build event'. When I do so this is displayed in the code display....


Private Sub Noed_Click()
Dim fld As Control

If Me.Check1 = True Then
For Each fld In Me.Controls
If fld.ControlType <> acLabel And fld.Name <> "Noed" Then
fld.Enabled = False
If fld.ControlType <> acCommandButton Then fld.Locked = True
End If
Next
Else
For Each fld In Me.Controls
If fld.ControlType <> acLabel And fld.Name <> "Noed" Then
fld.Enabled = True
If fld.ControlType <> acCommandButton Then fld.Locked = False
End If
Next
End If


End Sub

When I use my form and then go to tick the box, this error comes up....


The expression on click you entered as the event property setting produced the following error: A problem occured while Tele Address - Business data was communicting with the OLE server or ActiveX control.

* The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]
* There may have been an error evaluating the function, event, or macro.
 
Oops!

Just changed this..... If Me.Noed = True Then

Still no go though!
 
uhhh ... So you have this, then ...

Private Sub Noed_Click()
Dim fld As Control

If Me.Noed= True Then

hmmm ...
Try this first. I'm guessing you have an ActiveX Control, or some other funky control on this form that does not have the properties Enabled or Locked. Check out all of the Control Types in Access Help. You may need to exclude these as well:
If fld.ControlType <> acLabel And fld.ControlType <> acCustomControl And fld.Name <> "Noed" Then

Otherwise ...
This error points to other issues in your DB, not this code. Perhaps a reference to a library that is not registered or missing.
While in code view, go up to Tools, References ... on the menu bar. Are there any marked MISSING? If so, search this forum for missing reference. There is a lot on this. What ActiveX controls are you using in the DB? Make a copy of the DB, delete ActiveX controls one at time, re-running this code each time to find out which ActiveX Control/library is causing you an issue.
 
Thanks pdx_man... I'm away now for the weekend. I'll give it a try Monday morning and let you know then. I appreciate your help on this.... have a good one!
 
Thanks for your help pdx_man.... I can see that there is a lot of old bits and pieces of code laying around in this db. So I will do a copy and delete all the old stuff and see how I get on. Your code works just great on some of my other DB's, so thanks!
 
Well nearly there...! I cleaned out ALL the code from my form, and any buttons etc.., and inserted your code into what is now a bare data entry form. The read only function works ok but has this error when I tick the checkbox Run-Time Error '438' - Object dosen't support this property or method - When I go into debug: fld.Enabled = False is highlighted - The same happens when I remove the tick: fld.Enabled = True. This seems crazy when you consider I only have a few fields and labels left!
 
It's a bit late to join this debate but ...

I normally use a command button to switch my forms between read-only and editable. Give the following code a try:

Private Sub cmdAllowEdits_Click()

With Me.cmdAllowEdits
If .Caption Like "*Read-only*" Then
.Caption = "Click to make form editable"
Me.AllowEdits = False
Else
.Caption = "Click to make form Read-only"
Me.AllowEdits = True
End If
End With
Me.Refresh

End Sub


shay :cool:

PS You need to put a command button on your form and call it cmdAllowEdits. (Sorry if this is obvious but I was recently accused of confusing someone because I hadn't spelt out every step they needed to take to use my code!)
 
I usually tackle this with two versions of the same form, one read only and the other allowing edits, and a button to toggle.

But them I'm just a dirty hacker, and not a proper developer!
 
Success!! Don't understand why this happened? I made a copy of my form, deleted the original, re-named the new form to the old one, and no more code errors!! I tried your code shay... it's perfect for what I want! Work's a treat!..... Thanks to everyone for your time and effort! :)
 
Oh yes... shay... You forgot to mention to make sure your caption was named *Read-only* (ha, ha) :p
 
Can this be abstracted?

Is there a way to accomplish this within a module? I want to abstract the enabling/disabling of controls so that the module can look at the Tag property of each control and use it to decide whether or not to enable it.
 
hollering said:
Is there a way to accomplish this within a module? I want to abstract the enabling/disabling of controls so that the module can look at the Tag property of each control and use it to decide whether or not to enable it.

I've not read the post but is this what you want?

Code:
Public Function EnableControls(ByVal f As Form) As Boolean
    On Error Goto Err_EnableControls
    Dim ctl As Control
    For Each ctl In f.Controls
        ctl.Enabled = ctl.Tag = "*"
    Next 
    EnableControls = True
Exit_EnableControls:
    Set ctl = Nothing
    Exit Function
Err_EnableControls:
    EnableControls = False
    Resume Exit_EnableControls
End Function
 

Users who are viewing this thread

Back
Top Bottom