Help

J

James

Hello I have set some of my own security on a database and
I have this code:

If UsrUserID = 3 Then
TheSubForm.Locked = True
TheText.Caption = Warning
End If

I would like to know how I can lock all fields for editing
and everything to those users who have a user level of 3
when they open a form.

Can this be achieved?

Many Thanks

James
 
R

RobFMS

James

There are 3 properties of a form that you should review:

..AllowEdits {True | False}
..AllowAdditions {True | False}
..AllowDeletions {True | False}

The help file will give you more specifics.

HTH

--

Rob

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Need to launch your application in the appropriate version of Access?
http://www.fmsinc.com/Products/startup/index.asp

Need software tools for Access, VB, SQL or .NET?
http://www.fmsinc.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
J

James

These I know but all I really need in my view is the
locked property.

This will then lock the data so that is is shown and
cannot be edited added or deleted...

Is there any way of achieving this so that it works with
the below code.

Basically I want the following code to run on open but
with some changes.

If usrlevel = 3 then
*code for selecting all fields goes here*.locked = true

else

*code for selecting all fields goes here*.locked = False

End If

Something along these lines is what I am after?

Could you please help?

Mnay Thanks

James
 
C

Cheryl Fischer

While I recommend Rob's solution as the most efficient, you could try
something like the following, modified to suit your purposes:

Dim ctl as Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox then
ctl.Locked = True
End if
Next ctl

You'll need to make sure that you exclude controls which do not have a
Locked property.
 
J

James

How do I exclude them? and all I have to put in front of
that is

if usrlevel = 3 then
Dim ctl as Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox then
ctl.Locked = True
End if
Next ctl

Would that work? If I ran it on open?

Many Thanks

James
 
C

Cheryl Fischer

How do I exclude them?

You'll probably only have a few types of controls on your form which are for
data entry, so just add additional If ... End If statements for those
particular ControlTypes.

Recommend your code look like:

Dim ctl as Control

if usrlevel = 3 then
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox then
ctl.Locked = True
End if

If ctl.ControlType = <next control type. then
ctl.Locked = True
End if
Next ctl
else
' Code here for what happens if usrlevel <> 3
end if

Yes, you should be able to run this in the form's Open event.
 
J

James

Thank You very much for this...

I have tried this and it gives the value of actextbox as
109 combo box as 111 and the list box as 110 what does
this mean?

Also its pulling up an error (on open) which says:
-----------------------------------------------------
Runtime error 91

object variable with block variable not set
-----------------------------------------------------
Whats this all about here is the code I have used:
-----------------------------------------------------

Dim ctl As Control

If usrlevel = 3 Then
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Locked = True
End If

Next ctl

For Each ctl In Me.Controls
If ctl.ControlType = acComboBox Then
ctl.Locked = True
End If

Next

For Each ctl In Me.Controls
If ctl.ControlType = acListBox Then
ctl.Locked = True
End If

Next ctl

Else
If usrlevel = 1 Or 2 Then
For Each crtl In Me.Controls
If ctl.ControlType = acTextBox Then <----- Error here
ctl.Locked = False
End If

Next

For Each ctl In Me.Controls
If ctl.ControlType = acComboBox Then
ctl.Locked = False
End If

Next

For Each ctl In Me.Controls
If ctl.ControlType = acListBox Then
ctl.Locked = False
End If

Next ctl

End If
End If
End Sub
----------------------------------------------------------

What have I done wrong?

I appreciate all the help that has been given on this... :)

Many Thanks

James
 
R

RobFMS

James

There are 3 properties of a form that you should review:

..AllowEdits {True | False}
..AllowAdditions {True | False}
..AllowDeletions {True | False}

The help file will give you more specifics.

HTH


--

Rob

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Need to launch your application in the appropriate version of Access?
http://www.fmsinc.com/Products/startup/index.asp

Need software tools for Access, VB, SQL or .NET?
http://www.fmsinc.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
C

Cheryl Fischer

Based on the error message you are receiving, I would say that you are
missing a reference, perhaps to the DAO xx.x library.
I have tried this and it gives the value of actextbox as
109 combo box as 111 and the list box as 110 what does
this mean?

ControlTypes are stored as numbers; however, Access does make available
Intrinsic Constants for these values to make them easier to use and identify
in your code. Check VB Help on "ControlType" to see all of them.

Also, in your code, you are re-initializing the For...Next loop for each
control type. This is unnecessary - the loop examines each control type.
Your code should look like:

Dim ctl as Control

for each ctl in me.Controls
If usrLevel = 3 then
if ctl.ControlType = acTextBox then
ctl.Locked = true
end if

if ctl.ControlType = acComboBox then
ctl.Locked = true
end if
else
if ctl.ControlType = acTextBox then
ctl.Locked = False
end if

if ctl.ControlType = acComboBox then
ctl.Locked = False
end if
End If
next ctl


As you can see, you are writing quite a lot of code to do what the following
would take care of in a lot fewer lines:

If usrLevel = 3 then
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletions = False
else
' No else required here, as the default for each of these form
properties would be True
End if
 
J

James

Many Thanks For this

James
-----Original Message-----
Based on the error message you are receiving, I would say that you are
missing a reference, perhaps to the DAO xx.x library.


ControlTypes are stored as numbers; however, Access does make available
Intrinsic Constants for these values to make them easier to use and identify
in your code. Check VB Help on "ControlType" to see all of them.

Also, in your code, you are re-initializing the For...Next loop for each
control type. This is unnecessary - the loop examines each control type.
Your code should look like:

Dim ctl as Control

for each ctl in me.Controls
If usrLevel = 3 then
if ctl.ControlType = acTextBox then
ctl.Locked = true
end if

if ctl.ControlType = acComboBox then
ctl.Locked = true
end if
else
if ctl.ControlType = acTextBox then
ctl.Locked = False
end if

if ctl.ControlType = acComboBox then
ctl.Locked = False
end if
End If
next ctl


As you can see, you are writing quite a lot of code to do what the following
would take care of in a lot fewer lines:

If usrLevel = 3 then
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletions = False
else
' No else required here, as the default for each of these form
properties would be True
End if



--
Cheryl Fischer
Law/Sys Associates
Houston, TX




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top