Baber62
asked on
Disable Combo Box once user has selected item from list
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.
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.
What if they make a mistake and select the wrong option?
ASKER
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.
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.
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
So, in your code get the comboBox_SelectedIndex event and in there:
If ComboBox1.SelectedIndex <> -1 then
ComboBox1.enabled=false
End If
ASKER
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.
Where do I enter this code? On the before update or the after update event?
Please note that I am using MS Access 2003.
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
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
ASKER
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".
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".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Routine works perfectly!!!
Cheers
The control could be disabled (or hidden or simply ignored) once the data is used.