Solved

Deny editing text box until after list box selection

Posted on 2011-09-13
18
253 Views
Last Modified: 2012-05-12
I am struggling with something that should be very simple. I have a text box on a subform that I do not want to allow the user to type anything into until after they make a selection in a list box on the main form. The subform is not bound to the main form.
0
Comment
Question by:dlogan7
  • 11
  • 4
  • 3
18 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 300 total points
ID: 36532174
Try these two pieces of code on the MAIN form.

Private Sub Form_Load()
Me.YourSubFormName.Form.YourTextBoxName.Enabled = False
End Sub

Private Sub YourListBoxName_AfterUpdate()
    Me.YourSubFormName.Form.YourTextBoxName.Enabled = Not IsNull(Me.YourListBoxName)
End Sub

This assumes a Single Select List box.

mx
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 200 total points
ID: 36532267
I believe you can get by with one line in your subform's Current Event:

Me.txtYourTextbox.enabled = Not IsNull(me.Parent.lstYourListBox)
0
 
LVL 75
ID: 36532283
So, you come to a new record ... current triggers ... list box is null ... text box disabled. Good.
Then ... selection is made on list box - current event not triggered, text box still disabled.  Not Good.

mx
0
 
LVL 75
ID: 36532285
However ... we do need that code in the current event to cover existing records.

mx
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36532412
Also, better to use the ItemsSelected count rather than the actual value (null/not null) of the listbox to cover all bases.

The value won't work for a multi select listbox - it will be null regardless of selections.

A more general (single and multi select) check would be:

If Me.ListBoxName.ItemsSelected.Count > 0  Then ' (this means there are items selected)

Open in new window

0
 
LVL 75
ID: 36532424
Right ... which is why mentioned Single Select.

mx
0
 

Author Comment

by:dlogan7
ID: 36532847
I am getting an error message when using the line below in the OnLoad event of the main form.

Me.frmCallCommentLog.Form.Comment.Enabled = False

By the way, the list box is Single Select.

Error message:
 image
0
 
LVL 75
ID: 36532874


Me.frmCallCommentLog.Form.Comment.Enabled = False

Be sure what you put where it's BOLD above is what you see in the Name property of the SubForm Control on the Main form ...

mx
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36532876
I believe that's because the subform is not loaded yet.

Try moving that code to a later event such as the Current event (which fires as part of a form's opening sequence of events, and when the user changes to a different record)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 75
ID: 36532889
So ... in image example below, it would be:



Me.fsubA.Form.Comment.Enabled = False
Capture1.gif
0
 
LVL 75
ID: 36532905
You can also try this:

Private Sub Form_Load()
Me.YourSubFormName.SourceObject = "YourFormNameForTheSubform"
Me.YourSubFormName.Form.YourTextBoxName.Enabled = False
End Sub
0
 
LVL 75
ID: 36532922
Also, generally ... subform controls load before the main form.

mx
0
 

Author Comment

by:dlogan7
ID: 36533170
One "minor" item I overlooked. Instead of main and sub, it's actually main, sub1,and sub2. List box is on sub1, text box is on sub2. Don't think this would matter.

Mx, I am using the name of the control as you show above.

Now one of my forms has become corrupt. I think. I get an error on opening. It's a OnLoad event error. Nothing in any of the OnLoad events. I'm importing all objects into a new db.

0
 
LVL 75
ID: 36533216
"Don't think this would matter. "
Oh yeah.

ok then ... assuming sub 2 is not on SUB 1 ??



This goes in Sub 1:
Private Sub YourListBoxName_AfterUpdate()
    Me.Parent.YourSubFormTwoName.Form.YourTextBoxName.Enabled = Not IsNull(Me.YourListBoxName)
End Sub

And you will need what mbizup suggested also ... in the Current Event - of Sub 2 (where text box is):

    Me.YourTextBoxName.Enabled = Not IsNull( Me.Parent.YourSubFormOneName.Form.YourListBoxName)

0
 

Author Comment

by:dlogan7
ID: 36533335
Sub 2 is on Sub 1
0
 
LVL 75
ID: 36533384
What about sub 3 ...?

ok then ...

This goes in Sub 1 - shorting up the notation - substitute your names
Private Sub listBox_AfterUpdate()
    Me.fsub2.Form.txtBox.Enabled = Not IsNull(Me.listBox)
End Sub

fsub2 is the Name of the subform control on Sub 1


And again you will need what mbizup suggested also ... in the Current Event - of Sub 2 (where text box is):

Me.txtBox.Enabled = Not IsNull( Me.Parent.listBox)

mx

just kidding about sub 3 ...
0
 

Author Comment

by:dlogan7
ID: 36535055
Finally. Everything works perfectly.

Trust me, I hate going down to a sub2 situation. This is being driven by the requests of the client. He wants EVERYTHING on one form. It's so bad that we ended up exceeding the max width of 24". So, I went with a tab control in an attempt to squeeze things in tighter. Tab controls can't live on Tab controls, so I needed another set of subforms. If I had everything to do over again, it would be much different.

Thanks to both of you for your help.

Dale
0
 
LVL 75
ID: 36537601
You are welcome.

mx
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

11 Experts available now in Live!

Get 1:1 Help Now