Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an edit-button to unlock forms in Access 1

Status
Not open for further replies.

AapBanaan

Programmer
Aug 21, 2008
4
NL
I've been trying for 2 days straight to get Access to creat a simple 'edit' button, which changes the status of all fields in the form to .AllowEdits = true.

I read the FAQ, and used the code provided there, but it just won't work. I've set all fields to locked in the properties window, and I use this code for the 'on-click' event of my button:

Private Sub Knop2_Click()

Me.AllowAdditions = True
Me.AllowEdits = True
'if there's no subform don't include the rest of the code
For Each myControl In Controls
Select Case myControl.ControlType
Case acSubform
myControl.Form.AllowAdditions = True
myControl.Form.AllowEdits = True
End Select
Next

End Sub

Now when I open my form, the fields are nicely locked, but when I click the button, they just remain locked. What am I doing wrong?
 
Hi, you might try using the control's tag properties instead.


dim Ctl as Control

For Each ctl In Me.Controls

If ctl.Tag = "aValue" Then

ctl.Enabled = True

End If

Next

Hope that helps

 
Since you have all fields set to locked, you need to unlock them. Something like....
Code:
Dim ctl as Control
For Each ctl in Me
    If ctl.Type = acTextbox Then
        Me.ctl.Locked = False
    End If
Next ctl

Randy
 
I'll give it a whirl in the morning. Thanks for the tips sofar
 
Still doesn't work. For the button click event, this is now my code:

Code:
Private Sub Knop2_Click()

Dim ctl As Control

For Each ctl In Me
    If ctl.Type = acTextBox Then
        Me.ctl.Locked = False
    End If
Next ctl

End Sub

I get an error in this line:

If ctl.Type = acTextBox Then

and it selects the statement ".ctl" in "Me.ctl.locked", claiming that it does not recognise the method.

@dRahme: your statement doesn't do anyting at all (I don't get an error, but the text box just stays locked)
 
I think that this is overkill. There is no need to both lock the controls and to set AllowEdits to false. I think you should pick one, probably AllowEdits to false.


Code:
Dim ctl As Control

For Each ctl In Me.Controls
    If ctl.ControlType = acTextBox Then
        ctl.Locked = False
    End If
Next ctl
 
Your code works Remou. Finally I can get to work on the rest of the form. Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top