Solved

RECORD LEVEL LOCKING IN SUBFORM

Posted on 2013-11-19
7
527 Views
Last Modified: 2013-11-20
Is there a way to lock a single field in one row of data in a continuous subform?

I have a main form that has invitation numbers that is linked to a subform called children that displays all invited children. In the subform there is a checkbox called attended. If the child attends the event, this box is checked. Once checked, it becomes locked and not editable unless an admin logs in. An invitation number can be related to one child or more within the same family.

However, when I locked the checkbox on the after update property when the value = yes, all records related to the invitation number is locked. Sometimes only 2 out of 4 children attends even though the 4 has been invited.

Any assistance will be appreciated.
0
Comment
Question by:ernie_shah
  • 4
  • 3
7 Comments
 
LVL 57
ID: 39659362
The thing to realize is that with continuous forms, all rows will show the same value for a control if the control is unbound (no control source).

So first thing is, you need to bind it to a field.

Second thing is that any un-locking/locking of a record the way you want is a bit tricky.   One of the restrictions of being able to move to a record is that there is at least one editable control.

So typically what I do is:

1. Place a text control at the start of the row which has a width of zero.
2. In the OnCurrent event, which fires when a record receives the focus, I check what ever conditions I want to see if the record should be "locked" or "unlocked".

3. Based on that, I then do:

Me.<somecontrol>.Enabled = False

and possibly

Me.<somecontrol>.Locked = True

depending on how I want it to look for all controls but the one created in step #1.

 This allows you to move to each record because there is always one unlocked/enabled control available.

Jim.
0
 

Author Comment

by:ernie_shah
ID: 39659554
I have a field called attended that stores the value either Yes or No and it is bound to my table.

On the oncurrentevent of the subform, I have the few lines of code:
Private Sub Form_Current()
If Me!Attended.Value = Yes Then
    Me!Attended.Locked = True
Else: Me!Attended.Value = No
    Me!Attended.Locked = False
End If

End Sub

But it does not work
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 39660394
Sorry for the delay.

<<But it does not work >>

Watch this check:

If Me!Attended.Value = Yes

If this is bit field then what you'd want is:

 If Me!Attended.Value = True then

 Yes/no is just formatting.   Put a breakpoint or STOP before the line.   When you hit that, you can then use F8 to step through the code, hover over vairables and references to see the value, or use the debug window.

 Hit F5 to continue execution.

Jim.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:ernie_shah
ID: 39662337
Ok great, thanks so much this works.

Also, I want an admin user to be able to login to make edits.
I have a command button named unlock that allows the login dialog to open.
On successfully logging on, I want the records to be editable and attended to be unlocked.

I have included these two lines of code

Forms![mainformname].[subformname].Form.AllowEdits = True
Forms!mainformname!subformname.Form.attended.Locked = False

However, this only works for othe first record (one child)and not to all the records related to a single invitation number
0
 
LVL 57
ID: 39662381
<<However, this only works for othe first record (one child)and not to all the records related to a single invitation number >>

You must have code else where that is setting those values back, which is probably OnCurrent.

You'll need a 'flag' to indicate if the form has been unlocked or not.  That can be a module level variable, or a hidden text control on the main form.  Let's say it's a text control called txtUnlockFlag

In your unlock button code, you'll set this flag so that it's "true" (could be a control just containing a "Y").  By default it would be "false" (i.e. blank).

Now in the OnCurrent Code, it would look like this:

   If Me![txtUnlockFlag] = "Y" then
      ' An admin has un-locked the form.  Make sure it's editable
      Me.AllowEdits = True
      Me.attended.Enabled = True
      Me.attended.Locked = False
   Else
      ' Form is not open.  If attended has already been set, then leave it locked
      ' Only admins can change the attended field once it's been set.
     
      <your existing code here>

   End If

  That might not be 100% (not sure if your changing the enabled property or where your setting the allow edits on the subform), but you in outline that's what you need to do.

Jim.
0
 

Author Comment

by:ernie_shah
ID: 39663391
Thank you much Jim for your time and assistance.
0
 
LVL 57
ID: 39663513
No problem.  Glad to help.

Jim.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now