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
Solved

Deny editing text box until after list box selection

Posted on 2011-09-13
18
276 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 - 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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…
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…

839 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