Results 1 to 6 of 6
  1. #1
    ann06 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    6

    Question how to cancel the record in subform if clicked cancel on parent form before save.

    Hi,
    I have a form and a subform in it. I added New \ cancel button in the form so that the the user can cancel the record creation and no record will be inserted in the parent table.


    but when details are entered in the subform (a datasheet) row records will be created in the subform table. what is the correct method or how to cancel these records if the user choose to click cancel button on the parent form.
    thank you

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    One way is to hide the subform until the user saves the data in main form.
    If (Me.Something)= True Then
    Me.subformname.[Form].Visible = True
    Else
    Me.subformname.[Form].Visible = False
    End If
    HTH

  3. #3
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    I don't know the answer with clarity, but I think you could look into the Workspace Object in the help file. As an example, if changes to records were being made with code you could do something kinda like this:
    Dim myWS As Workspace
    Set myWS = DBEngine.Workspaces(0)

    myWS.BeginTrans
    ' Insert a block of code here that makes changes to various records
    If MsgBox("You have changed XXXXXXXX. Save the changes?", vbQuestion + vbYesNo) = vbYes Then
    myWS.CommitTrans 'If .CommitTrans is called, the changes are solidified.
    Else
    myWS.Rollback 'If the Rollback method is called, all the _
    'changes made since the .BeginTrans method are reversed.
    End If

    myWS.Close
    Set myWS = Nothing

    ...But you're not looking to rollback changes made from code, rather, changes made from a manual form entry. This is just a suggested avenue for undoing stuff since the Workspace method seems to allow for it. Good luck,
    Matt

  4. #4
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    I don't think it can be done without code. Another possibility that I now think is more appropriate is the use of the .OldValue property: http://msdn.microsoft.com/en-us/libr...ffice.15).aspx

    Below is some code I nabbed from that link to show how an Undo button is made:

    Private Sub btnUndo_Click()

    Dim ctlTextbox As Control

    For Each ctlTextbox in Me.Controls
    If ctlTextbox.ControlType = acTextBox Then
    ctlTextbox.Value = ctl.OldValue
    End If
    Next ctlTextbox

    End Sub

  5. #5
    ann06 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2013
    Posts
    6
    regarding the last answer , but the new row will still be there in the table right unless i explicitly delete?

  6. #6
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    You're right, the code I linked from the help file is only a skeleton for removing the values in textbox controls. I suppose you could opt to just delete a record that's already entered. I'm no pro, but I think some code you can use in a module to delete a record looks like this:

    Sub DeleteCurrent()

    Dim myR As Recordset
    Set myR = CurrentDb.OpenRecordset("YourTableNameHere", dbOpenDynaset)

    myR.FindFirst "[YourPrimaryKeyFieldName] = 'ValueYouWantToDelete'"

    myR.Delete
    myR.Close
    set myR = Nothing

    End Sub

    For the FindFirst line, it would be easy if it were a static value like so:
    myR.FindFirst "[PersonsNameField] = 'Joanne'"
    But I think your button needs to find out what Record you're looking at on the Form.

    With that in mind, let's pretend your table is called Orders (and the Primary Key field is called lets say "OrderID"). Next, let's look at the form you've made with all the controls on them that represent this Orders table (including and Undo button you're trying to program). One of the textboxes contains the OrderID, and you may have named it something like 'txtOrderID'. With this in mind, the FindFirst method line above might look like this:
    myR.FindFirst "[OrderID] = " & txtOrderID.value

    That's likely as much help as I can be. Good luck,
    Matt

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 12-12-2013, 10:13 PM
  2. Replies: 7
    Last Post: 11-30-2013, 12:33 PM
  3. Cancel and Delete Record
    By Loc in forum Programming
    Replies: 3
    Last Post: 07-11-2013, 02:50 AM
  4. Cancel new record
    By oakoen in forum Forms
    Replies: 11
    Last Post: 12-18-2010, 09:26 AM
  5. Replies: 4
    Last Post: 04-01-2009, 11:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums