Solved

RECORD LEVEL LOCKING IN SUBFORM

Posted on 2013-11-19
7
540 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

734 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