Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disable Combo Box once user has selected item from list

Posted on 2011-02-15
10
Medium Priority
?
1,476 Views
Last Modified: 2012-05-11
I have a combo box on a form with four items in the list. Once the item has been selected, I would like to disable the combo box. As users can inadvertently change the item by selecting the combo box and using the drop down menu listing the items.
Is there anyway to prevent this from happening? Perhaps test the field and see if it is blank then allow the user to select from the drop down menu and if it is not blank the combo box loses focus not allowing the user to change the entry previously entered.
0
Comment
Question by:Baber62
[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
10 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34895152
Disabling the control as soon as anything has been selected wouldn't give the user the chance of correcting an erroneous selection.

The control could be disabled (or hidden or simply ignored) once the data is used.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 34895154
What if they make a mistake and select the wrong option?
0
 

Author Comment

by:Baber62
ID: 34895212
If an erroneous selection is made this could be corrected by going to the table view and correcting it from there. I am more concerned with users changing it from the form view.

The database is one for Road Safety Audits of which there are only four types of audits namely Stage 1, Stage 1/2, Stage 3, and Stage 4. These are the items in the combo box.
0
Independent Software Vendors: 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!

 
LVL 7

Expert Comment

by:klakkas
ID: 34895303
For the comboBox control, if the user has not selected anything, the .SelectedIndex property is -1. If the .SelectedIndex is different than -1 then a selection has been made.

So, in your code get the comboBox_SelectedIndex event and in there:

If ComboBox1.SelectedIndex <> -1 then
     ComboBox1.enabled=false
End If
0
 

Author Comment

by:Baber62
ID: 34895476
klakkas,

Where do I enter this code? On the before update or the after update event?

 Please note that I am using MS Access 2003.
0
 
LVL 6

Expert Comment

by:JVWC
ID: 34895881
Here is an "Opt Out" code ...

Private Sub Combo1_AfterUpdate()
    If MsgBox("Are you sure of this selection?" & vbCr & Me.Combo1.Text, vbCritical + vbOKCancel, "Selection will be locked!") = vbCancel Then
    Me.Combo1 = "" 'assuming text
Else
    Me.cboNextCtrl.SetFocus 'move focus to another control so we can lock the original combobox1
   'then
    Me.Combo1.Locked = True
End If
End Sub

'In case you need to move to another record and start over
Private Sub Form_Current()
Me.Combo1.Locked = False
End Sub


Cheers
JC
0
 

Author Comment

by:Baber62
ID: 34895975
JVWC,

My combo box is combo10, however, just in the line after the else statement on "Me.cboNextCtrl.SetFocus" it give me a debug error and states that "Method or data member not found".
0
 
LVL 6

Accepted Solution

by:
JVWC earned 2000 total points
ID: 34904414
<"Me.cboNextCtrl.SetFocus" it give me a debug error and states that "Method or data member not found".>

Yes, you cannot lock the control that has the focus, so you need to move the focus to another control on the form. I called it "cboNextCtrl" as logic would suggest you move the focus to the "NEXT CONTROL" that the user would use.
Assuming that you will have other Combo controls for the user to select, I guess the logic follows that you would move the focus to the NEXT combo...

Change Me.cboNextCtrl.setfocus to the name of a control on your form thus:
me.yourcontrolname.setfocus.



Cheers
JC
Private Sub Combo10_AfterUpdate()
    If MsgBox("Are you sure of this selection?" & vbCr & Me.Combo10.Text, vbCritical + vbOKCancel, "Selection will be locked!") = vbCancel Then
    Me.Combo10 = "" 'assuming text
Else
    Me.changethistoyourcontrolname.SetFocus 'move focus to another control so we can lock the original combobox1
   'then
    Me.Combo10.Locked = True
End If
End Sub

'In case you need to move to another record and start over
Private Sub Form_Current()
Me.Combo10.Locked = False
End Sub

Open in new window

0
 

Author Closing Comment

by:Baber62
ID: 34905414
Routine works perfectly!!!
0
 
LVL 6

Expert Comment

by:JVWC
ID: 34905877
Cheers
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

705 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