Run-time error '2115'

ovello

Registered User.
Local time
Today, 22:07
Joined
Jul 14, 2005
Messages
17
I have a form with a subform(I suppose it doesn`t matter too much). I set an AfterUpdate method for the last component (combo box) of the form. That method should retrieve the values of all the fields of the form and send them into a database. For that I need to set the focus on the each component of the form. But, unfortunatelly, when I want to set the focus on the first component (which is an enabled and active field), I get the following error:

"Validation Rule property for this field is preventing Microsoft Access from saving data in the field."

How can I solve this problem?

The code look like the above one:

Code:
Private Sub cboAdrese_AfterUpdate()

    ' Declar variabilele auxiliare
    Dim vNRCDA, vtxtCodPartn, vcboAdrese As String
    
    NRCDA.SetFocus
    vNRCDA = NRCDA.Text
    
'    txtCodPartn.SetFocus
'    vtxtCodPartn = txtCodPartn.Text
'    cboAdrese.SetFocus
'    vcboAdrese = cboAdrese.Text
    
    MsgBox vNRCDA
    MsgBox vtxtCodPartn
    MsgBox vcboAdrese
    
End Sub
This code runs, but I get the error listed above. More than that, the vNRCDA variable is displayed correctly.

OK, if I try the next code:

Code:
Private Sub cboAdrese_AfterUpdate()

    ' Declar variabilele auxiliare
    Dim vNRCDA, vtxtCodPartn, vcboAdrese As String
    
    NRCDA.SetFocus
    vNRCDA = NRCDA.Text
    
'    txtCodPartn.SetFocus
'    vtxtCodPartn = txtCodPartn.Text
    cboAdrese.SetFocus
    vcboAdrese = cboAdrese.Text
    
    MsgBox vNRCDA
    MsgBox vtxtCodPartn
    MsgBox vcboAdrese
    
End Sub
then I get the previous error, and, after it, I get another one:

Run-time error '2115':

Validation Rule property for this field is preventing Microsoft Access from saving data in the field.

How can I solve the problem?

Thank you in advance!
 
Is there a reason you are not using bound controls on your form? They do all of the work for you.
 
RuralGuy said:
Is there a reason you are not using bound controls on your form? They do all of the work for you.

Yes, it is. I use combo boxes for example and I cannot imagine how can I bound them to the fields of a table. More than that, my first field need an update (GotFocus) before validating/entering the data. I saw that when I bound the fields of the form to a table, I cannot set defauld values for those fields.
 
Binding a ComboBox to a field in a query/table limits the data the user can put in that field to whatever the RowSource of the cbo contains. It also allows the programmer to put cryptic data (like a foreign key for example) in the field while displaying the Description of the FK so the user can make a reasonable selection.

The default value in a bound ComboBox should work just fine when the field in the underlying query/table has no value "IsNull([Field])". I'm sorry if I did not understand you correctly.
 
I had the same error in a same situation.
I tried to setfocus to a textbox and then write there some value in an afterupdate event.
Although i got the error, the text in the textbox was correct.

Is there any possibility to get around that error?
(so it wouldn't be displayed, but the code would still be executed)

Thanks for some wise thoughts.

PS!
I don't want to bind any objects.
 
Last edited:
gillbates21,
Please start a new thread so everyone can see and help.
 

Users who are viewing this thread

Back
Top Bottom