?
Solved

RECORD LEVEL LOCKING IN SUBFORM

Posted on 2013-11-19
7
Medium Priority
?
546 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 58
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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 58
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 58
ID: 39663513
No problem.  Glad to help.

Jim.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

801 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