Protect Data in a Combo Box (1 Viewer)

TheSearcher

Registered User.
Local time
Today, 05:04
Joined
Jul 21, 2011
Messages
304
I have a combo box using a query for a rowsource. I have the "Limit to List" property set to Yes and the "Allow Value List Edits" property set to No. But the user can still change or delete the data - and this causes the program to crash. If I set the "Locked" property to Yes then nothing can be selected. What can I do to protect the data in my combo box?

Thanks,
TS
 

RuralGuy

AWF VIP
Local time
Today, 03:04
Joined
Jul 2, 2005
Messages
13,826
Use the BeforeUpdate event to qualify the changes.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:04
Joined
May 7, 2009
Messages
19,170
use the NotInList event of the combo:

Private Sub combo_NotInList()
Response=acDataErrDisplay
end sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:04
Joined
Feb 19, 2002
Messages
42,981
Are you saying that the user is able to change the combo's rowsource values? Not possible unless the ControlSource of the combo is bound to the same table as the RowSource and that is most definitely an error.
 

missinglinq

AWF VIP
Local time
Today, 05:04
Joined
Jun 20, 2003
Messages
6,423
...But the user can still change or delete the data...

Or are you saying that the user can simply delete a selection that has been made or enter a value by typing it into the Combobox...and this is what you want to prevent?

Linq ;0)>
 

TheSearcher

Registered User.
Local time
Today, 05:04
Joined
Jul 21, 2011
Messages
304
Pat Hartman - The combo box is not bound to any table. It's rowsource is an sql query that executes in the "on open" event of the form.
Missinglinq - Yes that is correct. The user can actually delete the contents of the combo box leaving a null value and thereby causing the program to crash. I addressed this by putting code in both the "Before Update" and "After Update" events to check for a null value. That seems to be working.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:04
Joined
Feb 19, 2002
Messages
42,981
It's rowsource is an sql query that executes in the "on open" event of the form.
A rowSource bound to a query, is bound to the underlying tables.

I see that you've found the form's BeforeUpdate event. That is the correct event to use to do this validation. Make sure you are canceling th update when you encounter an error. Remove the validation code from the AfterUpdate event. It isn't doing anything productive.

If a column is ALWAYS required, you should also set its required property to Yes on the table.
 

Users who are viewing this thread

Top Bottom