Run-time error '2115'

T

Tony Girgenti

When i run the following code in the after update event for a check box, i
get:

"Run-time error '2115' the macro or function set to the BeforeUpdate or
ValidationRule property for this field is prventing Microsoft Access from
saving the data in the field" on the second line of this code.

If i click END, it goes back to the form with the combobox field filled in
with "First".

How can i change a combo box's text when i check a check box next to it ?

Any help appreciated.
Thanks,
Tony

If Me.StrItmChk = True Then
Me.StrItm.SetFocus
Me.StrItm.Text = """First"""
Me.StrItm.Enabled = False
Me.StrItmChk.SetFocus
StartItem = Hex(0)
Else
Me.StrItm.SetFocus
Me.StrItm.Text = ""
StartItem = Hex(255)
Me.StrItm.Enabled = True
End If
 
S

Sandra Daigle

Hi Tony,

Instead of setting focus to the control 'strItm' so that you can use the
text property to assign a value, just assign the value directly -

me.strItm="First"

Note that you don't need the extra quotes unless you want the saved text
value to include the quotes. You can change the enabled property without
setting focus to the control - in fact, you can not change enabled to false
while the control has the focus.
 
T

Tony Girgenti

Hi Sandra. Thanks for your help with this.

The problem is, if i don't change the focus to the control whose text
property i want to change i get the following error
"Run-time error '2185': You can't reference a property or method for a
control unless the control has the focus"

Also, i do want the text of the control to appear as "First" with the
quotes.

Any help that you can provide to do what i want to do would be greatly
appreciated.

Thanks,
Tony

Sandra Daigle said:
Hi Tony,

Instead of setting focus to the control 'strItm' so that you can use the
text property to assign a value, just assign the value directly -

me.strItm="First"

Note that you don't need the extra quotes unless you want the saved text
value to include the quotes. You can change the enabled property without
setting focus to the control - in fact, you can not change enabled to false
while the control has the focus.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Tony said:
When i run the following code in the after update event for a check box, i
get:

"Run-time error '2115' the macro or function set to the BeforeUpdate or
ValidationRule property for this field is prventing Microsoft Access from
saving the data in the field" on the second line of this code.

If i click END, it goes back to the form with the combobox field filled in
with "First".

How can i change a combo box's text when i check a check box next to it ?

Any help appreciated.
Thanks,
Tony

If Me.StrItmChk = True Then
Me.StrItm.SetFocus
Me.StrItm.Text = """First"""
Me.StrItm.Enabled = False
Me.StrItmChk.SetFocus
StartItem = Hex(0)
Else
Me.StrItm.SetFocus
Me.StrItm.Text = ""
StartItem = Hex(255)
Me.StrItm.Enabled = True
End If
 
S

Sandra Daigle

Hi Tony,

In Access the Text Property has a differnet purpose than in VB. In Access
you are really setting the Value property of the control and the control
does not need to have the focus. Make sure you change assignment to one of
the following:

me.strItm="""First"""
' or
me.strItm.value="""First"""

The value property is the default property of the control so you do not have
to explicitly specifiy it.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.


Tony said:
Hi Sandra. Thanks for your help with this.

The problem is, if i don't change the focus to the control whose text
property i want to change i get the following error
"Run-time error '2185': You can't reference a property or method for a
control unless the control has the focus"

Also, i do want the text of the control to appear as "First" with the
quotes.

Any help that you can provide to do what i want to do would be greatly
appreciated.

Thanks,
Tony

Sandra Daigle said:
Hi Tony,

Instead of setting focus to the control 'strItm' so that you can use
the text property to assign a value, just assign the value directly -

me.strItm="First"

Note that you don't need the extra quotes unless you want the saved
text value to include the quotes. You can change the enabled
property without setting focus to the control - in fact, you can not
change enabled to false while the control has the focus.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Tony said:
When i run the following code in the after update event for a check
box, i get:

"Run-time error '2115' the macro or function set to the
BeforeUpdate or ValidationRule property for this field is prventing
Microsoft Access from saving the data in the field" on the second
line of this code.

If i click END, it goes back to the form with the combobox field
filled in with "First".

How can i change a combo box's text when i check a check box next
to it ?

Any help appreciated.
Thanks,
Tony

If Me.StrItmChk = True Then
Me.StrItm.SetFocus
Me.StrItm.Text = """First"""
Me.StrItm.Enabled = False
Me.StrItmChk.SetFocus
StartItem = Hex(0)
Else
Me.StrItm.SetFocus
Me.StrItm.Text = ""
StartItem = Hex(255)
Me.StrItm.Enabled = True
End If
 

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