Help Cancel update or moveprevious causing problem

abujafar

Registered User.
Local time
Today, 08:11
Joined
Oct 14, 2008
Messages
14
The code is giving me hell

I have some buttons on a subform I am using to control a parent form.

I am trying to write code to cancel a new record.

The cancelupdate and moveprevious methods do not seem to work. After I click cancel the new record still exist and it does not move to the previous record.

I am using Access 2007 and Windows Vista Home premium

Code:
Private Sub cmdCancel_Click()
On Error GoTo Err_cmdCancel_Click

    Dim intConfirmCancel As Integer
    
    intConfirmCancel = MsgBox("Are you sure you want to cancel this record", vbYesNo, "Confirm Delete")
    
    If intConfirmCancel = vbYes Then
                
        Me.Parent.Form.Recordset.CancelUpdate
        
        SetButtons (False)
        
        If Me.Parent.CurrentRecord > 1 Then
            
            
            Me.Parent.Form.Recordset.MovePrevious

            
        End If
        
    End If
Exit_cmdCancel_Click:
    Exit Sub

Err_cmdCancel_Click:
    MsgBox Err.Description
    Resume Exit_cmdCancel_Click
    
End Sub

I hope someone can assist me
 
Are you using transactions? Do you know when a MainForm and SubForm save records and when it is no longer possible to undo that action?
 
Are you using transactions? Do you know when a MainForm and SubForm save records and when it is no longer possible to undo that action?

No I am not using transactions. No I do not now when I can no longer undo a record.
 
When you move the focus from a MainForm to a SubForm, if the MainForm Recordsource is Dirty the the MainForm record will be saved and no longer available to UnDo. The same is true when you attempt to move the focus from a SubForm to basically anywhere else, if the SubForm RecordSource is Dirty then the Current Record will be saved and no longer available to UnDo. Getting rid of those records then requires a Delete of the record.
 
When you move the focus from a MainForm to a SubForm, if the MainForm Recordsource is Dirty the the MainForm record will be saved and no longer available to UnDo. The same is true when you attempt to move the focus from a SubForm to basically anywhere else, if the SubForm RecordSource is Dirty then the Current Record will be saved and no longer available to UnDo. Getting rid of those records then requires a Delete of the record.

This is weird. I just changed the command from cancel update to delete and it caused an error that said the record cannot be deleted because there is a related record in payroll.
Payroll is a related many side table that is attached as a subform. There is actually no records in there because the period record was just added.

However once I move away from the record and then go back I can delete the record. Weird really weird.:confused:
 
Keep playing with it. It will start to make sense after a while.
 
Keep playing with it. It will start to make sense after a while.

I will. Thanks I really appreciate the assistance.

One quick question though, do you know if access automaticcally inserts a related record for subforms.

I am trying to figure out why access is saying there is a related record for a record i just started adding.
 
One quick question though, do you know if access automaticcally inserts a related record for subforms.

I am trying to figure out why access is saying there is a related record for a record i just started adding.
The simple answer is *no* unless the user Dirties the record. It might be an anomoly of the Cascading updates and deletes. I don't use those two features but do the work myself.
 

Users who are viewing this thread

Back
Top Bottom