Solved

Deny editing text box until after list box selection

Posted on 2011-09-13
18
262 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
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)

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…

911 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

16 Experts available now in Live!

Get 1:1 Help Now