Solved

Locking/unlocking fields on a subform within a subform

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

733 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