undo subform

patatrac

Registered User.
Local time
Today, 15:15
Joined
Jan 17, 2010
Messages
46
hy for all
is possible in a form with a button exit clear a subform:rolleyes:
 
as soon as you leave the subform, the record/entries are saved.
you could reset the focus to the subform then delete the record.
 
exactly when i click in a subform immediatelly assign id of the principal form, and after is no possible undo nothing.
is possible look an example please...
thanks a lot
 
you could use the On Exit event of the subform to ask the user if they want to save the record. if No, Me.Undo.
 
Use the BeforeUpdate event of the subform to verify changes
 
I tried with beforeupdate but not working...
i think wrong rutine code
 
i never use bound controls so I can't say i've ever had to use the On Dirty event. however, ignore the dirty event and maybe use the AfterInserte event because it is record level and not field level. like:

Code:
Private Sub Form_AfterInsert()
     dim response as integer
     response = Msgbox("Do you want to save this record?", vbYesNo, "Save record")
     If response = vbNo then
           Me.Undo
     Else
           Msgbox("Record not saved")
     End if
End Sub


hope this works
 
THANKS
this code work with 1 recordset add in subform,
but if subform is a datasheet and add 2 recordset don't work
 
actually, that was the wrong event. patratac rightly said the event to use, BeforeUpdate. paste the code provided into that event.
 
Is good code but unfortunattely no work well with datasheet subform whit most of one record
thanks a lot
This situation is many spoken in all forum but there is no well definitive solution .I think that this is a trouble of access very important to resolve in the new release if possible.....
 
Last edited:
Is good code but unfortunattely no work well with datasheet subform whit most of one record
thanks a lot
This situation is many spoken in all forum but there is no well definitive solution .I think that this is a trouble of access very important to resolve in the new release if possible.....



i was actually supposed to say as "Rich" said re the BeforeUpdate event:). i've just tested it and it works perfectly. are you sure you've got that event on the subform's BeforeUpdate event? not on the main form. it may be a little sticky too if the subform is dependent on other parent tables

post your database (that is if you want to). zipped of course.
 
Your logic doesn't seem to be right. You need to understand what the Undo function does. Undo does not remove a record that was added, it rolls back to the old value of the control on that record. Reconsider your design

what you are looking to achieve is complicated (for the intermediate vba programmer).

a much efficient way of rolling back to the old values of the current form's controls (and not the subform) is this:

Code:
    Dim ctrl As Control

    For Each ctrl In Me.Controls
        If ctrl.ControlType = acTextBox Then
           ctrl.Value = ctrl.OldValue
        End If
    Next
 
Thanks
I think that this is big problem to resolve in access.
I hope in the next release this problem find the most easy solution
 
it isn't really a problem patatrac. like i said your thoughts of Undo is flawed. you cannot "undo" a record already created, you delete it. if you don't interrupt it in it's BeforeUpdate event then you must delete it and not undo. i hope my explanation was clear
 

Users who are viewing this thread

Back
Top Bottom