Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

Yesterday I discussed a Combobox I was adding dummy header lines into.

See that message here: The Joys of Combo Dropdown Group Headers.

My combo box is multiple columns and I use the extra columns to insert data into other fields on the line when the Item Description is selected. I do this in a BeforeUpdate event for the combo box control. This event passes in a “Cancel” parameter that if you set to true will prevent the update from occuring. Here is the code I’m using:

Private Sub Item_Description_BeforeUpdate(Cancel As Integer)
   If Me.Item_Description.Column(1) = "" Then Cancel = True
   If Cancel = True Then Me.Undo
End Sub

Something to note. “Me” is actually referring to the form, not the control. If anything else has been updated but not committed to the underlying datasource yet, it will be “Undone”. In my case I don’t need to worry about it. I have code handling the saving of the form after most updates and I do actually want to revert any change up to this point if it hasn’t been saved to the db yet.

You could also just undo this control only by changing Me.Undo to Me.Item_Description.Undo.

If you don’t include this step, you’ll get behavior where the change is still there and it appears nothing has happened. The user will likely get confused, but could hit escape at this point (which does an undo) and move to another control.

I didn’t have any other problems associated with this, but I did end up adding dashes in front of my Group Titles to make them more readable. Happy coding everyone.