Solved

Locking/unlocking fields on a subform within a subform

Posted on 2011-09-15
3
358 Views
Last Modified: 2012-05-12
I have a subform (subB) nested in another subform (subA), which is nested in the Main form.

On subB I have code in the OnOpen event that is supposed to lock or unlock a text field on subB if a checkbox is checked on subB.

The checking/unchecking of the checbox is working, dataset is getting updated, and the editing of the text box is working.  However, the locking/unlocking behavior is not.

Is there a problem with my syntax in the OnOpen event of subB?



Private Sub Form_Open(Cancel As Integer)

If Forms![Main]![subA]![subB]!chkCheck = 0 Then
   
    Forms![Main]![subA]![subB]!txtField.Locked = True
  
ElseIf Forms![Main]![subA]![subB]!chkCheck = -1 Then

    Forms![Main]![subA]![subB]!txtField.Locked = False


End If

End Sub

Open in new window

0
Comment
Question by:cogc_it
3 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 300 total points
ID: 36546326
Seems you would only need this ..

Private Sub Form_Open(Cancel As Integer)
   
    Me.txtField.Locked = Not Me.chkCheck
 
End Sub


And you might want to use the Current event instead:

Private Sub Form_Current()
   
    Me.txtField.Locked = Not Me.chkCheck
 
End Sub
0
 
LVL 20

Assisted Solution

by:GrahamMandeno
GrahamMandeno earned 200 total points
ID: 36546330
Use the AfterUpdate event of the checkbox to lock/unlock the textbox:
Private Sub chkCheck_AfterUpdate()
txtField.Locked = (chkCheck=0)
End Sub

Open in new window

Then you can also call chkCheck_AfterUpdate anywhere else in your code where the value of chkCheck might have changed - for example, moving from one record to another:
Private Sub Form_Current()
Call chkCheck_AfterUpdate
End Sub

Open in new window


Best wishes,
Graham
0
 

Author Closing Comment

by:cogc_it
ID: 36561970
DatabaseMX:  I moved the event to the On Current event and it solved my problem.

GrahamMandeno:  Your elaboration on using the On Current event was very helpful in helping to figure out why the behavior wasn't working as expected and will help in forms development going forward.  

I put the On Current event on the Main and subB form in this instance.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

746 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