Solved

Deny editing text box until after list box selection

Posted on 2011-09-13
18
279 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
[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
  • 11
  • 4
  • 3
18 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

730 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