Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389

    Data auto save problem with sub form

    I am using following code to prevent access to autosave data, unless I press save button.
    Form top
    Code:


    Private SaveRecord As Boolean

    Form Current
    Code:


    SaveRecord = False

    Form Before update
    Code:


    If SaveRecord = False Then
    Cancel = True
    Me.Undo
    Cancel = False
    End If

    cod on Save button (on click)
    (along with other fields conditons)
    Code:


    SaveRecord = True

    This works fine without any problem for one form (without subform).
    Problem:
    But I have problem, when I have subform


    With above, If I jump to subform, data filled in Main form is deleted.
    If I dont use above code, data of main form is saved before I type something in subform and then confirm to save records by pressing save button.
    (I can undertand, the code before update is deleting Mainform records, but solution?)

    How can I solve this issue to add data of Mainform and subform at the same time, after I press save button.
    1) Prevent the main form to autosave
    2) meanwhile I can add data to subform
    Finally press save
    Note: I dont want yes/no popup messages for confirmation.

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    The short answer is no.
    As soon as you move to the subform Access will attempt to save the record on the main form, which triggers your automatic dismissal of the main forms data.
    The answer would probably be to not enable the subform (when you are on a new record) until the main form record is saved.

    I would delete your other 2 posts, no need to ask the same question three times.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Please do not crosspost the same question, here or in other forums.
    You might think you will get more attention, but likely would be the opposite.

    Crosspost is frowned upon in most forums.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    ohh sorry i does not know about three times rules.

  5. #5
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    can you please provide me a sample access file of this with simple coding.....please

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by deepaksharma View Post
    can you please provide me a sample access file of this with simple coding.....please
    Have you read Minty's comments in post #2
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Do not use the Undo command, just use Cancel?
    However you are now working against Access and not with it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    but i want the data not to be saved until the save button is clicked

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by deepaksharma View Post
    but i want the data not to be saved until the save button is clicked
    I believe the Cancel will do that?
    The Undo undoes the changes, hence it's name.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    can you please provide me a sample file of this with simple coding

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by deepaksharma View Post
    can you please provide me a sample file of this with simple coding
    You have what you need, just remove the undo.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    if i do this then whenever the form will be closed without completing it will auto save in the data table which i don't want i want the data to be saved in the table when the save button is clickrd

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    How is it going to save the data if you issue cancel all the time?
    Have you walked through your code to test?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    you are right. my coding perfectly work with a single main form but it disturb when i use a sub form with this.

  15. #15
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    So set the Subform to enabled = false or hide it until they press save?
    There is no point be able to enter or save subform data if you aren't going to save the main form data.

    You can check on the current event if it's a new record, and if not enable or display the sub form.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 02-15-2016, 09:34 PM
  2. Replies: 6
    Last Post: 01-08-2016, 04:25 PM
  3. form - save entered data only with save button
    By cbrxxrider in forum Forms
    Replies: 3
    Last Post: 10-20-2013, 12:39 PM
  4. Replies: 5
    Last Post: 02-05-2013, 10:57 PM
  5. Replies: 1
    Last Post: 08-22-2012, 01:24 PM

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