Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error 2115 on combobox selection

I have a combobox on a form and I'm trying to programmatically select one of the items in the combobox after I've run my SQL query on the access database. I use the following code to iterate over the items and set the selected item:

'Make the appropriate location appear in the combobox
For i = 0 To cboLocations.ListCount - 1
  If Me.cboLocations.Column(0, i) = locindex Then
    Debug.Print "locindex: " & locindex & vbCrLf & " Me.cboLocations.Column(0, i):" & Me.cboLocations.Column(0, i)
    Me.cboLocations.SetFocus
    Me.cboLocations.ListIndex = i '<<< error 2115
    Exit For
  End If
Next i

As indicated, I keep getting error 2115: The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Access from saving the data in the field.

Neither of the properties for this combobox indicated in the error message is set to anything. So I'm stuck. Please advise.

like image 560
Alan Avatar asked Oct 10 '15 18:10

Alan


2 Answers

programmatically select one of the items in the combobox

The way I've always done that is to assign something to the combo's Value like this ...

Me.MyCombo.Value = "target text"

Value comes from the Bound Column of the combo's selected row. (You can find Bound Column on the Data tab of the combo's property sheet.) Conversely, assigning "target text" to Value selects the matching row.

In your situation, I think you're trying to select the combo row which contains the same text as your locindex variable. And if that is true, then I think all you need is this ...

Me.cboLocations.Value = locindex

As far as when you do that, neither Before Update nor Validation Rule seems like the right choice to me. I suggest you do it from whatever code you're using to run your "SQL query on the database", immediately after the query.

like image 90
HansUp Avatar answered Oct 05 '22 00:10

HansUp


You are probably colliding with the BeforeUpdate event.

Try using AfterUpdate.

like image 36
Gustav Avatar answered Oct 05 '22 00:10

Gustav