Error 2115 Updating Bound Text Box from Listbox Selection

LarryB

Registered User.
Local time
Today, 10:14
Joined
Jun 19, 2012
Messages
66
Hi all,

I have created user input form and to help with ease of input, I have decided to pull records in to a list box, user selects an item and the item updates to the bound text box field. The textbox populates but produces an error and I cannot continue unless I clear the text box.

run time error '2115'. The macro or function set to the BeforeUpdate or Validation rule for this field is preventing MS Access from Saving the data in the field.

Oddly, I can type the data in the bound field and tab on through the form until I save the record.

My setup

Form bound to tblMain
txtACode.text bound to tblMain!ACode
txtISIN.text bound to tblMain!ISIN

To help with selection of the appropriate records

Code:
 Private Sub cmdAgentSearch_Click()
  
 bAgentSearch = True
lstSearch.RowSource = "qryDistributionASearch"
 
End Sub
My query pulls in ACode & AName data from TblA with criteria
Like [Forms]![frmDistributionAddEdit]![txtAgentCode] & "*"

This helps with searching and the listbox is populated accordingly.

On the form in the List box After Update event, I have tried setting the text box directly, an unbound text box and now a variable and all 3 fail with the error. The text box is populated

Code:
 Private Sub lstSearch_AfterUpdate()
    Dim sPopulate       As String
    If bAgentSearch = True Then
        sPopulate = lstSearch.Column(0)
        MsgBox sPopulate
        txtACode.SetFocus
        txtACode.Text = sPopulate
    Else
        sPopulate = lstSearch.Column(0)
        txtISIN.SetFocus
        txtISIN.Text = sPopulate
    End If
    
    bAgentSearch = False
 End Sub
Should I be using the AfterUpdate event of the listbox? Are there any other suggestions to allow a user to select data if they start typing part of the required field entry?
 
afterupdate is correct,
but where is the error...which line does it fail?
 
Hi RanMan. If I click debug on the error it highlights the row where I fill the text box

txtAcode.text = sPopulate

or

txtISIN.text = sPopulate

The text box is populating with the required data selection but the error appears after that.

Should I give the focus back to the listbox?
 
Any reason why you are mucking about with the .Text property? If not then simply remove it.

Is there a BeforeUpdate? Then what is the code.
 
Thanks Spike, your reference to my text property twigged it. I removed the setfocus lines from behind the lstbox afterupdate event and referenced the text box .value properties rather then .text property.

Cheers
 

Users who are viewing this thread

Back
Top Bottom