Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RECORD LEVEL LOCKING IN SUBFORM

Posted on 2013-11-19
7
Medium Priority
?
550 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

636 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