unprotect 1 datafield in protected form

  • Thread starter Thread starter herwig
  • Start date Start date
H

herwig

Hello,

In my database, different users can login with a password
I want to protect a form that contains very much fields if the user has
login code 'hbevoe = 1', BUT 1 search field (naampje) can be filled in.
If the user has another login code, he can fill in al the fields (or
change).

I'm able to lock that form, but how can I unlock that search field?
I have following code on a button that opens that form:
-------------
Private Sub Knop6_Click()
On Error GoTo Err_Knop6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTest"

If HBevoe = 1 Then

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly

Forms![frmTest]![naampje].Locked = False


Else

DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

Exit_Knop6_Click:
Exit Sub

Err_Knop6_Click:
MsgBox Err.Description
Resume Exit_Knop6_Click

End Sub
 
Opening a form in read only mode will prevent any editing of values in
controls.

What you need to do is to set the Locked property of all controls to No (in
the design view of the form). Then you can use code in the OnLoad event of
the form to "look back" at the password (use the OpenArgs argument of the
OpenForm command) and unlock the one control if appropriate. Something like
this for your "click" event of the Knop6 control:


Private Sub Knop6_Click()
On Error GoTo Err_Knop6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTest"

DoCmd.OpenForm stDocName, , , stLinkCriteria, , , CStr$(HBevoe)

Exit_Knop6_Click:
Exit Sub

Err_Knop6_Click:
MsgBox Err.Description
Resume Exit_Knop6_Click

End Sub


Then, in the OnLoad event of the form, you could use code similar to this:

Private Sub Form_Load()
If Me.OpenArgs = "1" Then Me.naampje.Locked = False
End Sub


Additionally, you can use code to set all controls to locked position (just
in case something were to happen and the form were accidentally saved with
some controls unlocked) and then to unlock the control if desired:

Private Sub Form_Load()
Dim ctl As Control
On Error Resume Next
For Each ctl in Me.Controls
ctl.Locked = True
Next ctl
If Me.OpenArgs = "1" Then Me.naampje.Locked = False
End Sub
 
Thank you Ken,
I'll try this out

herwig

Ken Snell said:
Opening a form in read only mode will prevent any editing of values in
controls.

What you need to do is to set the Locked property of all controls to No (in
the design view of the form). Then you can use code in the OnLoad event of
the form to "look back" at the password (use the OpenArgs argument of the
OpenForm command) and unlock the one control if appropriate. Something like
this for your "click" event of the Knop6 control:


Private Sub Knop6_Click()
On Error GoTo Err_Knop6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTest"

DoCmd.OpenForm stDocName, , , stLinkCriteria, , , CStr$(HBevoe)

Exit_Knop6_Click:
Exit Sub

Err_Knop6_Click:
MsgBox Err.Description
Resume Exit_Knop6_Click

End Sub


Then, in the OnLoad event of the form, you could use code similar to this:

Private Sub Form_Load()
If Me.OpenArgs = "1" Then Me.naampje.Locked = False
End Sub


Additionally, you can use code to set all controls to locked position (just
in case something were to happen and the form were accidentally saved with
some controls unlocked) and then to unlock the control if desired:

Private Sub Form_Load()
Dim ctl As Control
On Error Resume Next
For Each ctl in Me.Controls
ctl.Locked = True
Next ctl
If Me.OpenArgs = "1" Then Me.naampje.Locked = False
End Sub


--
Ken Snell
<MS ACCESS MVP>

herwig said:
Hello,

In my database, different users can login with a password
I want to protect a form that contains very much fields if the user has
login code 'hbevoe = 1', BUT 1 search field (naampje) can be filled in.
If the user has another login code, he can fill in al the fields (or
change).

I'm able to lock that form, but how can I unlock that search field?
I have following code on a button that opens that form:
-------------
Private Sub Knop6_Click()
On Error GoTo Err_Knop6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTest"

If HBevoe = 1 Then

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly

Forms![frmTest]![naampje].Locked = False


Else

DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

Exit_Knop6_Click:
Exit Sub

Err_Knop6_Click:
MsgBox Err.Description
Resume Exit_Knop6_Click

End Sub
 
Hei Ken,

I've incorporated your solution in my database and worked it out
This works fine !

thanks again
;-))


herwig


Ken Snell said:
Opening a form in read only mode will prevent any editing of values in
controls.

What you need to do is to set the Locked property of all controls to No (in
the design view of the form). Then you can use code in the OnLoad event of
the form to "look back" at the password (use the OpenArgs argument of the
OpenForm command) and unlock the one control if appropriate. Something like
this for your "click" event of the Knop6 control:


Private Sub Knop6_Click()
On Error GoTo Err_Knop6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTest"

DoCmd.OpenForm stDocName, , , stLinkCriteria, , , CStr$(HBevoe)

Exit_Knop6_Click:
Exit Sub

Err_Knop6_Click:
MsgBox Err.Description
Resume Exit_Knop6_Click

End Sub


Then, in the OnLoad event of the form, you could use code similar to this:

Private Sub Form_Load()
If Me.OpenArgs = "1" Then Me.naampje.Locked = False
End Sub


Additionally, you can use code to set all controls to locked position (just
in case something were to happen and the form were accidentally saved with
some controls unlocked) and then to unlock the control if desired:

Private Sub Form_Load()
Dim ctl As Control
On Error Resume Next
For Each ctl in Me.Controls
ctl.Locked = True
Next ctl
If Me.OpenArgs = "1" Then Me.naampje.Locked = False
End Sub


--
Ken Snell
<MS ACCESS MVP>

herwig said:
Hello,

In my database, different users can login with a password
I want to protect a form that contains very much fields if the user has
login code 'hbevoe = 1', BUT 1 search field (naampje) can be filled in.
If the user has another login code, he can fill in al the fields (or
change).

I'm able to lock that form, but how can I unlock that search field?
I have following code on a button that opens that form:
-------------
Private Sub Knop6_Click()
On Error GoTo Err_Knop6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTest"

If HBevoe = 1 Then

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly

Forms![frmTest]![naampje].Locked = False


Else

DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

Exit_Knop6_Click:
Exit Sub

Err_Knop6_Click:
MsgBox Err.Description
Resume Exit_Knop6_Click

End Sub
 
Glad to hear it! Good luck.

--
Ken Snell
<MS ACCESS MVP>

herwig said:
Hei Ken,

I've incorporated your solution in my database and worked it out
This works fine !

thanks again
;-))


herwig


Ken Snell said:
Opening a form in read only mode will prevent any editing of values in
controls.

What you need to do is to set the Locked property of all controls to No (in
the design view of the form). Then you can use code in the OnLoad event of
the form to "look back" at the password (use the OpenArgs argument of the
OpenForm command) and unlock the one control if appropriate. Something like
this for your "click" event of the Knop6 control:


Private Sub Knop6_Click()
On Error GoTo Err_Knop6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTest"

DoCmd.OpenForm stDocName, , , stLinkCriteria, , , CStr$(HBevoe)

Exit_Knop6_Click:
Exit Sub

Err_Knop6_Click:
MsgBox Err.Description
Resume Exit_Knop6_Click

End Sub


Then, in the OnLoad event of the form, you could use code similar to this:

Private Sub Form_Load()
If Me.OpenArgs = "1" Then Me.naampje.Locked = False
End Sub


Additionally, you can use code to set all controls to locked position (just
in case something were to happen and the form were accidentally saved with
some controls unlocked) and then to unlock the control if desired:

Private Sub Form_Load()
Dim ctl As Control
On Error Resume Next
For Each ctl in Me.Controls
ctl.Locked = True
Next ctl
If Me.OpenArgs = "1" Then Me.naampje.Locked = False
End Sub


--
Ken Snell
<MS ACCESS MVP>

herwig said:
Hello,

In my database, different users can login with a password
I want to protect a form that contains very much fields if the user has
login code 'hbevoe = 1', BUT 1 search field (naampje) can be filled in.
If the user has another login code, he can fill in al the fields (or
change).

I'm able to lock that form, but how can I unlock that search field?
I have following code on a button that opens that form:
-------------
Private Sub Knop6_Click()
On Error GoTo Err_Knop6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTest"

If HBevoe = 1 Then

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly

Forms![frmTest]![naampje].Locked = False


Else

DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

Exit_Knop6_Click:
Exit Sub

Err_Knop6_Click:
MsgBox Err.Description
Resume Exit_Knop6_Click

End Sub
 
Back
Top