run-time error 2115

H

Hank Megens

Hello,

In a form I use a combo box to give people a self chosen number
So after giving out a number I don't want to see it anymore in my combobox
when I edit the next record.
So I created the next VBA statement:

Private Sub koppelkasnummer_Beforeupdate(Cancel As Integer)
DoCmd.SetWarnings False
DoCmd.OpenQuery "query1"
Me.Requery
DoCmd.Close , acQuery, "query1"
DoCmd.SetWarnings True
End Sub

but by giving out the first number I get the following error:

- Runtime error '2115'
The macro or function set to the BeforeUpdate or ValidationRule property for
this field is preventing Microsoft Access from saving the data in the field.

Query1 = updating my list, so my other query (on which the combolist is
based will be updated)

How to slove this?
 
D

Douglas J. Steele

You can't put code like that in the BeforeUpdate event of a control. Try
putting it in the AfterUpdate event.

Of course, you'd be better off using something like:

Private Sub koppelkasnummer_AfterUpdate()
CurrentDb().QueryDefs("query1").Execute
Me.Requery
End Sub

And actually, that's just going to requery the form. To requery the combo
box, you need the name of it there:

Me.NameOfComboBox.Requery
 
H

Hank Megens

Douglas,

this works almost.
If I go to the next record, the number I connected to the previous record is
still visible. this goes on and on.
How can I solve this?

Hank Megens
 
D

Douglas J. Steele

What's the SQL of the query you're trying to run? Is koppelkasnummer the
name of the combo box?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top