Solved

Locking/unlocking fields on a subform within a subform

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Normalization of a table 19 73
sql statement - 9 24
Calculation in Access 5 26
Access Open Report with SQL Parameter 11 30
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

770 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