How to solve the "runtime error 2115"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thomashoyle
    New Member
    • Mar 2012
    • 1

    #1

    How to solve the "runtime error 2115"

    Hi, I have a database-form with a couple of text boxes in it.
    I want to replace the first letter that is written in a
    text box with an uppercase letter, so I use the "after update" event and have written the following code:

    Code:
    Private Sub straatenhuisnummer_AfterUpdate()
    dim anaam as string
    anaam = Forms!medewerker!straatenhuisnummer.Text
    anaam = UCase(Left(anaam, 1))
    Forms!medewerker!straatenhuisnummer.Text = anaam
    End Sub
    When the code is performed, I get the following
    error, which states "the macro or function set to the beforeupdate or validationrule property for this field is preventing Microsoft Access from saving the data in this field".
    Can anyone help me with this? thanks!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    You are updating the control in the control's own AfterUpdate event procedure. That doesn't make much sense does it ;-)

    Try using BeforeUpdate instead :
    Code:
    Private Sub straatenhuisnummer_BeforeUpdate(Cancel As ...)
        With Me
            .straatenhuisnummer = Mixcase(.straatenhuisnummer)
        End With
    End Sub
    Also, please don't post code you've typed in directly in future. It wastes our time and isn't greatly appreciated. See Before Posting (VBA or SQL) Code.

    Comment

    Working...