Solved

Locking/unlocking fields on a subform within a subform

Posted on 2011-09-15
3
362 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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