Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing Values From being entered into Combo Box 3

Status
Not open for further replies.

campbere

Technical User
Oct 10, 2000
146
US
I would like to have a combo box on my form and prevent users from entering values. I would use the dropdown style (#2) that prevents this but it makes the combobox read only which is a problem for the application. I need to be able to let the application write to it, but not allow a user to type any values into it. Is there an easy way of doing this?
 
You've tried using the enabled/locked property? Stevie B. Gibson
 
Field Properties/Limit to list = True

(-: ide
 
Enabled = False doesnt work because the user won't be able to select from the drop down list. I need them to still be able to select from the drop down list, I just want to prevent them from entering any value they want.
 
The LimitToList property is present only in Access ComboBox Stevie B. Gibson
 
oh!-oh!-oh!
I was on a MS Access forum. If there are not any properties labelled: "limit to list", i'm sorry! :-o
;-)
ide
 
Yeah I was trying to find that and couldnt. Thanks for trying. Anyone else have an idea?
 
So use locked=true
You can write on in via code, the user can open the combo but not write on it....he have also to select a value? Stevie B. Gibson
 
Yes they have to be ablility to select a value from the list. So locked = true doesnt work. The only thing I am trying to prevent is them from typing in a value that doesn't exist. The only way I know of is to write if statements to say if what they type doesnt match a value in the drop down list to not allow it. I was just hoping there was a much easier cleaner way of doing it.
 
campbere:
I think you are mistaken with your first post where you state that the "...dropdown style (#2) that prevents this but it makes the combobox read only"

You can still add list items to the combo box via code.

Is this not a possibility?
 
I seemed to have a problem. It gives me an error the text property is read only.

What happens is that the combo box is intially loaded with with the first value of a multiple recordset. The user can update the value by selecting options from the drop down list. However they were also able to type in values which made some managers angry that non standard values were being used. So I decided to lock the field so they can only choose from the drop down.

The error occurs when you move to the next value in the recordset. So if the recordset has 3 records and the intially the combo box .text field is populated from the first record. For this example it will be Yahoo. But if the user goes to the next record and the value changes from Yahoo to IWON then an error is displayed that is the text value is read only.

Does this make sense? Sorry if I am confusing everyone. I am just trying to find an easy way of stopping non standard values from being entered.
 
Please correct me if I mis-understand:

It sounds like you have bound your combo box to a recordset.

If that is the case, I suggest you use the Microsoft DataCombo control instead of a Combo Box.
 
Set the style property to number three on the list. This should be done in the property window of the combo box
 
You can set the locked value to true on keydown and false on keyup this will not allow the user to type anyting in the combo box. example:

Private Sub cmbRateofInput_KeyDown(KeyCode As Integer, Shift As Integer)
cmbRateofInput.Locked = True
End Sub

Private Sub cmbRateofInput_KeyUp(KeyCode As Integer, Shift As Integer)
cmbRateofInput.Locked = False
End Sub
 
Hi
I had the same issue with a combo that I first populate using Sql on form_load. I wanted to be able to stop users adding their own data in the combo box but still wanted them to select or type in a value that was in the list. For this purpose i have written a small function that returns true or false when the text value of the combo is compared with the list values. The function is called from the validate event of the combo and takes the approriate action dependent upon the returned function value. Here is the function, hope it's of use?

Public Function InTheList(CheckList As ComboBox) As Boolean
'#############################################################
'## This takes the current text from the combo and compares ##
'## to each item in the list. If an item matched then the ##
'## function is set to True. Else set to False ##
'#############################################################

Dim x As Integer

If CheckList.ListCount > 0 Then

For x = 1 To CheckList.ListCount

If CheckList.Text = CheckList.List(x - 1) Then
InTheList = True
GoTo EndThisNow
Else
InTheList = False
End If

Next x
Else
InTheList = False
End If

EndThisNow:

End Function

Regards
Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top