Exclude object from Read Only? (1 Viewer)

GendoPose

Registered User.
Local time
Today, 14:31
Joined
Nov 18, 2013
Messages
175
Hi all, probably a silly question but is it possible to exclude certain boxes when a form is set to read only?

My database essentially has 4 user levels (Developer, Admin, User and Guest), and whenever a Guest opens up a form, the form opens as Read Only and a message box displays telling you this. However on most of these forms, there are search boxes which allows you go straight to a specific record, but they don't modify any data, but because the form is read only, I can't type in these comboboxes.

So is there anyway to exclude these boxes from being read only?

Thanks
 

Geotch

Registered User.
Local time
Today, 09:31
Joined
Aug 16, 2012
Messages
154
Instead of making the entire form read only just lock certain text boxes when the guest logs in.
 

GendoPose

Registered User.
Local time
Today, 14:31
Joined
Nov 18, 2013
Messages
175
I've tried this but for some reason, when I add
Code:
If Forms![Login]!AccessLevel = Guest Then cbo1.enabled = false
on the Form Open event, it prevents the form from opening when I either click on the button on my navigation form to open it, or go into the navigation pane and try to open it from there.
 

boblarson

Smeghead
Local time
Today, 07:31
Joined
Jan 12, 2001
Messages
32,059
You can do it in several ways. One I like to do is to set each control's Enabled property to NO in design view and then enable based on role. Put in the TAG property of the control the levels you want to have be able to edit data in that control like this -

If I wanted to let everyone have access I would use ALL in the tag. If I wanted only Developer, Admin and User to have access I would put Developer|Admin|User in the tag.

Then in the code I use this:

Code:
Dim ctl As Control
 
For Each ctl In Me.Controls
   ctl.Enabled = Instr(1, ctl.Tag, Forms!Login.AccessLevel) > 0
Next
 

GendoPose

Registered User.
Local time
Today, 14:31
Joined
Nov 18, 2013
Messages
175
Thanks for the replies, but I can't see how or where to put this information, any help?

I've tried putting this in the On Open event of a form, but it now prevents the form from opening again.
 

GendoPose

Registered User.
Local time
Today, 14:31
Joined
Nov 18, 2013
Messages
175
I've tried this code;
Code:
Private Sub Form_Open()
    If [Forms]![frmLogin]![Level] = "Guest" Then
        Me.JOBNO.Enabled = False
    Else
        Me.JOBNO.Enabled = True
    End If
End Sub

but now I get an error saying "Procedure declaration does not match description of event or procedure having the same name".
 

missinglinq

AWF VIP
Local time
Today, 10:31
Joined
Jun 20, 2003
Messages
6,423
You've apparently typed this in, freehand, rather than letting Access generate the Sub Header!

Private Sub Form_Open()

needs to be

Private Sub Form_Open(Cancel As Integer)

To be honest, though, I'd move this to the Form_Load event.

Linq ;0)>
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:31
Joined
Feb 19, 2002
Messages
42,970
Do NOT use the form's Open event for things involving data. The recordsource for the form has not yet been loaded when the Open event runs.

As Linq said, the best event for this particular situation is the form's Load event since the setting would not change based on which record you were viewing.

The best event to use when the code is dependent on a data value is the form's Current event. The Current event runs whenever the form navigates to a new record including the first one. For example, you might want to prevent updates to "closed" records so you need to navigate to the record before you know it is "closed". When you scroll to the next record, it might be "Open" and when the Current event runs, your locking/unlocking code will run to unlock the record.
 

GendoPose

Registered User.
Local time
Today, 14:31
Joined
Nov 18, 2013
Messages
175
Thanks for that guys, that's got it! I've done it on Form Load, as there won't be any closed records in my form (well at least right now anyways, who knows when it'll change!)

Thanks for the help!
 

Users who are viewing this thread

Top Bottom