Welcome to SPN

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

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

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. OP
    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)
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page