Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Re: Change event

Discussion in 'Information Technology' started by LCSIV, Jul 28, 2006.

Tags:
  1. LCSIV

    LCSIV
    Expand Collapse
    Guest

    Dirk,
    This is a helpful peace of code. How do you get it to not run if you are
    entering new information into a blank form?

    "Dirk Goldgar" wrote:

    > "Max" <Max@discussions.microsoft.com> wrote in message
    > news:65CEF5FE-B8CC-4A51-896B-763079C966B5@microsoft.com
    > > I would like to validate a Text field for any changes.
    > >
    > > if someone change the data in the filed I would like a MSGBOX to come
    > > up ask if they want to change the content of the text box, if yes
    > > then save the changes if not then Undo.
    > >
    > > This is what I have so far but it doesnt seem to be working.
    > >
    > > Private Sub TEXTBOX_Change()
    > > If MsgBox("are you sure you want to change the TEXTBOX
    > > content",vbYesNo, "Warning") = vbYes Then Me.TEXTBOX._____Not
    > > sure what to write here____________
    > > Else
    > > Me.TEXTBOX.Undo
    > > End If
    > > End Sub
    > >
    > > Thanks

    >
    > Don't use the Change event; not only will it not let you do what you
    > want, but it would ask that question for every keystroke the user makes
    > in the text box. That would be highly annoying.
    >
    > Instead, use the BeforeUpdate event -- that's where most data-validation
    > code belongs. It might look like this:
    >
    > '----- start of example code -----
    > Private Sub MyTextbox_BeforeUpdate(Cancel As Integer)
    >
    > If MsgBox( _
    > "Are you sure you want to change the value of MyTextbox?", _
    > vbQuestion+vbYesNo, _
    > "Warning") _
    > = vbNo _
    > Then
    > Cancel = True
    > Me.MyTextbox.Undo
    > End If
    >
    > End Sub
    > '----- end of example code -----
    >
    > --
    > Dirk Goldgar, MS Access MVP
    > www.datagnostics.com
    >
    > (please reply to the newsgroup)
    >
    >
    >
     
  2. Loading...


  3. Dirk Goldgar

    Dirk Goldgar
    Expand Collapse
    Guest

    "LCSIV" <LCSIV@discussions.microsoft.com> wrote in message
    news:FD68D89E-6B28-4B68-89D8-C349CD6988B0@microsoft.com
    > Dirk,
    > This is a helpful peace of code. How do you get it to not run if you
    > are entering new information into a blank form?
    >
    > "Dirk Goldgar" wrote:
    >

    [...]
    >>
    >> Instead, use the BeforeUpdate event -- that's where most
    >> data-validation code belongs. It might look like this:
    >>
    >> '----- start of example code -----
    >> Private Sub MyTextbox_BeforeUpdate(Cancel As Integer)
    >>
    >> If MsgBox( _
    >> "Are you sure you want to change the value of
    >> MyTextbox?", _ vbQuestion+vbYesNo, _
    >> "Warning") _
    >> = vbNo _
    >> Then
    >> Cancel = True
    >> Me.MyTextbox.Undo
    >> End If
    >>
    >> End Sub
    >> '----- end of example code -----


    Preface it with a test of the form's NewRecord property; e.g.,

    '----- start of example code -----
    Private Sub MyTextbox_BeforeUpdate(Cancel As Integer)

    If Not Me.NewRecord Then

    ' ... original code ...

    End If

    End Sub
    '----- end of example code -----

    --
    Dirk Goldgar, MS Access MVP
    www.datagnostics.com

    (please reply to the newsgroup)
     

Share This Page