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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box question

Status
Not open for further replies.

NRK

Technical User
Feb 13, 2002
116
US
I have a combo box that lists values. I set its values to 'Limit to List'. I have a button that says 'Add'. This pops up a message about how to add a value to the combo box and then sets focus on the combo box. After the user adds an entry, there is an 'AfterUpdate' that verifies that it is in the correct format, otherwise it creates an error message and undoes the entry.

My only problem is that users can still write in the combo box before clicking 'Add'. Access will create a Warning that their entry is not in the list, but this doesn't happen until after they have already typed in the combo box.

My question - is there a way to prevent users from typing anything in the combo box unless they click 'Add'?

Any advice would be much appreciated!
 
Okay this should work. In the On Change event for the combobox:

If Not InStr(1, Me.YourCombo.RowSource, Me.YourCombo.Text) > 0 Then
Me.YourCombo.Undo
End If JHall
 
JHall -
That works great, except for one condition. When the user tries to click 'Add', the combo box still won't allow for any values to be inputted into the field.

Is there some way to set that line of code to false and, then, reactivate it?
 
My question - is there a way to prevent users from typing anything in the combo box unless they click 'Add'?

Well, the specific answer to your question is " Unfortunately, NO." You can't keep the from getting into the combo box unless you mark it as "Locked", but as JHall156 has found, that severely restricts its' usefullness. You can TRAP any typing after the fact with the NOT IN LIST event, but you can't keep them from typing it in the first place.

Is your combo backed by a table somewhere? I assume your "add" process adds a new record to this table? Do you then remember to Requery the combobox to collect the new value?

This should be a very straightforward thing to do, we must be missing a step somewhere.

Remember, you're unique - just like everyone else
You're invited to visit another free Access forum:
or my site,
 
Create a global variable in your declarations bIsAdding as Boolean

In the click event of your add button
bIsAdding = True


In the onchange event of the combobox
If Not bIsAdding Then
If Not InStr(1, Me.YourCombo.RowSource, Me.YourCombo.Text) > 0 Then
Me.YourCombo.Undo
End If
bIsAdding = False
End If


You will probably need to tweak it a bit, but you get the idea... JHall
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top