Solved

RECORD LEVEL LOCKING IN SUBFORM

Posted on 2013-11-19
7
528 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

920 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

13 Experts available now in Live!

Get 1:1 Help Now