Solved

Deny editing text box until after list box selection

Posted on 2011-09-13
18
285 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

707 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