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

x
?
Solved

Locking/unlocking fields on a subform within a subform

Posted on 2011-09-15
3
Medium Priority
?
368 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
[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
3 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 1200 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 800 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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 …

610 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