Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to cancel a change on a textbox

Status
Not open for further replies.

ksbigfoot

Programmer
Joined
Apr 15, 2002
Messages
856
Location
CA
When a user goes into a text box, I copy the value to a hidden text box. Once the text box is changed and the user leaves the record (not just the field but up or down to a new record), on the OnExit event, I check to see if the data has changed. If it has, I prompt to user to see if this is what they want, If they choose Yes, everything works, but if they choose NO, then it doesn't work.
I get the following error: Run-time error '-2147352567 (80020009)'; the data has been changed.
I noticed that the BeforeUpdate event gets called before the ON_Exit event. In the BeforeUpdate event, I modify the UserID and ModifiedTime, but I don't touch the two text box fields.
Here is the code I have in my OnExit event:
Code:
Private Sub txtFromLegalName_Exit(Cancel As Integer)
Dim strMessage As String
Dim intResponse As Integer

    If Me.CurrentRecord = 2 Then
        strMessage = "Are you sure you want to modify the original record?"
        If Forms![Pipeline Assignment]![txtHiddenFieldValue] <> Me.txtFromLegalName Then
            intResponse = MsgBox(strMessage, vbOKCancel)
            If intResponse <> 1 Then
                'Cancel = True
                Me.txtFromLegalName.SetFocus
                Me.txtFromLegalName = Forms![Pipeline Assignment]![txtHiddenFieldValue]
            End If
        End If
    End If
End Sub
Thanks
 
After posting my question, I didn't know what order the events were happening. I checked and the AfterUpdate event is also called before the ON_Exit. I am changing my code in the After_Update event, so that is where I am getting my error message from.
I will change my logic and put the code from the On_Exit event into the After_Update event.
Thanks and sorry about the confusion.
 
Hi, I handle items like this slightly differently. I would start with the the user input in an unbound text box. That way I do not have to worry about exiting a record in edit mode, which I suspect may be your problem.

Something like:

unbound text box: txtPipeline

dim QResponse

txtpipeline after update()

msgbox ("You entered " & txtPipeline & " as the new value. Is this correct? ", vbyesno, "Question")

if Qresponse = vbyes then
then
me.txtpipeline = txtYourUpdated field
end if

....or something along those lines.

Hope that helps.




 
Hi dRahme,
Thanks for the suggestion.
I ended up not checking each text box as I leave it, I ended up checking all the fields at once I left the record.
Thanks again.
KS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top