Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-22-2014, 09:23 AM   #1
David R
I know a few things...
 
David R's Avatar
 
Join Date: Oct 2001
Location: Kansas City, MO, USA
Posts: 2,628
Thanks: 86
Thanked 149 Times in 148 Posts
David R is on a distinguished road
Form Control still 'saving' after Undo/Cancel

This frame controls an option group. If they are in an existing citation and want to start one for another type, this offers to write a new record in when they try to switch. Problem is, if it DOES write the new record, it seems to be saving the old record, and thus both will end up 56, for example. Access seems to be ignoring/overwriting the Me.frameCitationType.Undo (I don't want to use Me.Undo because they may have made other changes as well).

If the user does not spawn the new citation, it undoes fine. I suspect the problem may be the Filter/FilterOn?

Code:
Private Sub frameCitationType_BeforeUpdate(Cancel As Integer)
Dim chap As Integer
Dim othercit As Variant
Dim curRecord  As DAO.Recordset
Dim curDefend  As DAO.Recordset

    If Me.NewRecord = True And IsNull(Me.CaseNumber) Then
        MsgBox "Enter the Service Order and Increment first, please.", vbExclamation
        Me.frameCitationType.Undo
        Cancel = True
        Me.CaseNumber.SetFocus
        Exit Sub
    End If

    If DCount("*", "queryCitationViolations", "[CitationID] = " & Me.CitationID & " AND [ChapterID] <> " & Me.frameCitationType.Value) > 0 Then
        'first undo the edit so we don't jack everything up later
        chap = Me.frameCitationType.Value
        Me.frameCitationType.Undo
        Cancel = True

        othercit = DLookup("CaseNumber", "queryCountUnmailed", "[CaseNumber] = '" & Me.CaseNumber & "' AND [ChapterID] = " & chap)

        If Not IsNull(othercit) Then 'existing citation in the new category
            If MsgBox("There is an existing Chapter " & Me.frameCitationType.Value & " citation draft. Jump to it?", vbQuestion + vbYesNo, _
                      "This citation is for Chapter " & Me.frameCitationType.OldValue) = vbYes Then 'jump to it
                Me.Filter = "[CaseNumber] = '" & Me.CaseNumber & "' AND [ChapterID] = " & chap
                Me.FilterOn = True
            End If
        Else 'no other citation, let's offer to create it
            If MsgBox("Would like to create a new Chapter " & chap & " citation for this Service Order now?", vbQuestion + vbYesNo, _
                      "This citation is for Chapter " & Me.frameCitationType.OldValue) = vbYes Then 'jump to it
                Set curRecord = CurrentDb.OpenRecordset("tableCitations", dbOpenDynaset)
                Set curDefend = CurrentDb.OpenRecordset("SELECT tableDefendants.* FROM tableDefendants WHERE [CitationID] = " & Me.CitationID, dbOpenDynaset)
                Me.Parent.SetFocus
                'doCmd.RunCommand acCmdRecordsGoToNew
                
                With curRecord
                    .AddNew
                    !CaseNumber = Me.CaseNumber
                    !CitationType = chap
                    !CitationDate = Int(Now())
                    !FineAmount = 100 'default
                    !HearingDate = Me.HearingDate
                    !DelinquentDate = Me.DelinquentDate
                    !IncidentAddress = Me.IncidentAddress
                    !IncidentKIVAPIN = Me.IncidentKIVAPIN
                    !IncidentZIP = Me.IncidentZIP
                    !LegalDescription = Me.LegalDescription
                    !AdminID = Me.AdminID
                    !InspectorID = Me.InspectorID
                    !SupervisorID = Me.SupervisorID
                    othercit = !CitationID 'store the new one to jump to
                    .Update
                End With
                
                If curDefend.RecordCount > 0 Then
                    DoCmd.SetWarnings False
                    DoCmd.RunSQL "INSERT INTO tableDefendants ( CitationID, PersonName, PersonAddress, PersonCity, PersonState, PersonZIP, PersonCountry, PersonRelationship ) " & _
                                 "SELECT " & othercit & ", PersonName, PersonAddress, PersonCity, PersonState, PersonZIP, PersonCountry, PersonRelationship " & _
                                 "FROM tableDefendants WHERE [CitationID] = " & Me.CitationID
                    DoCmd.SetWarnings True
                End If
                
                If MsgBox("Do you want to go there now?", vbQuestion + vbYesNo, "New citation for Chapter " & chap & " drafted") = vbYes Then
                    Me.Filter = "[CitationID] = " & othercit
                    Me.FilterOn = True
                End If
                
                curRecord.Close
                Set curRecord = Nothing
                curDefend.Close
                Set curDefend = Nothing
            End If
        End If
    Else
        Me.subformViolations.SourceObject = "formViolations" & Me.frameCitationType.Value
        Me.subformViolations.Form.FilterOn = True
    End If
End Sub

__________________
Regards,
David R

Last edited by David R; 07-09-2014 at 08:50 AM. Reason: code updated since May; does not fix problem
David R is offline   Reply With Quote
Old 05-22-2014, 10:03 AM   #2
spikepl
Eledittingent Beliped
 
spikepl's Avatar
 
Join Date: Nov 2010
Location: San Serriffe
Posts: 6,144
Thanks: 77
Thanked 980 Times in 958 Posts
spikepl is a jewel in the rough spikepl is a jewel in the rough spikepl is a jewel in the rough
Re: Form Control still 'saving' after Undo/Cancel

BeforeUpdate of a control determines only whether or not the new value submitted for the control will be stored in the record - and not whether the entire record actually gets stored. Unless you force a save or make it go to another record, in which case Access automatically will attempt to save the entire record.

To prevent saving of a record you need to cancel the Form's BeforeUpdate.
__________________

Don't tell us what did not happen.
Do you tell the mechanic about your car "it doesn't work" or vague stuff like:
I couldn't, No joy, To no avail, No go
, Incorrect, Wrong, Seems, Without success, It didn't let me, I/it failed.

Do tell us what did happen
:

I want this ... to happen, I attempted this ..., using this ... code and pressing these buttons, the system did this ... in response, and I got this ... error in this ... line.

Did it help? Pass it forward!

Joys of Access:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

spikepl is offline   Reply With Quote
Old 05-22-2014, 10:54 AM   #3
David R
I know a few things...
 
David R's Avatar
 
Join Date: Oct 2001
Location: Kansas City, MO, USA
Posts: 2,628
Thanks: 86
Thanked 149 Times in 148 Posts
David R is on a distinguished road
Re: Form Control still 'saving' after Undo/Cancel

Aren't I reversing the value change, though?
Code:
        Me.frameCitationType.Undo
        Cancel = True
It's impossible to 'change' the value of the frame from within the BeforeUpdate event. My other option would be to fire it from AfterUpdate instead, but that sounds like a recipe for getting stuck in a loop...

__________________
Regards,
David R

Last edited by David R; 05-22-2014 at 11:08 AM.
David R is offline   Reply With Quote
Old 07-09-2014, 08:28 AM   #4
David R
I know a few things...
 
David R's Avatar
 
Join Date: Oct 2001
Location: Kansas City, MO, USA
Posts: 2,628
Thanks: 86
Thanked 149 Times in 148 Posts
David R is on a distinguished road
Re: Form Control still 'saving' after Undo/Cancel

Bumping. This is still/again a problem, and I can see no reason why.
Code:
If Me.NewRecord = True And IsNull(Me.CaseNumber) Then
        MsgBox "Enter the Service Order and Increment first, please.", vbExclamation
        Me.frameCitationType.Undo
        Cancel = True
        Me.CaseNumber.SetFocus
        Exit Sub
    End If
This is literally the first click on the form. There is NO reason it should be unable to undo itself (and no, I can't use Me.Undo because that would remove the user's valid edits, if they had made any).

__________________
Regards,
David R

Last edited by David R; 07-09-2014 at 08:37 AM.
David R is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a dialog form with HTML control that returns OK/Cancel morsagmon Modules & VBA 7 07-06-2010 12:53 PM
Cancel or undo mainform and subform Thinh Theory and practice of database design 2 01-30-2007 10:12 AM
Cancel and undo angelcoder Forms 1 06-01-2006 12:54 PM
Input mask prevents cancel or undo when adding new record TeriA Forms 9 08-23-2004 04:59 PM
[SOLVED] How to undo or prevent a record save from a cancel button? Jovalle Modules & VBA 3 05-18-2000 07:34 PM




All times are GMT -8. The time now is 07:46 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World