Results 1 to 5 of 5
  1. #1
    Beginner72 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2016
    Posts
    12

    Form creating empty records in source table


    First, I apologize if this has been answered somewhere already. I could not find an answer.

    I have a form which allows a user to enter purchase records into a source table. The user would enter fields such as invoice date, received date, cost, vendor, invoice number, department, etc. I have noticed that every time a value is entered into the form such as a date, a record is automatically created. If the user enters the date and closes the form, getting called away, an entry is stored in the table with just a date. Every so often I have to go into the source table and delete those empty records.

    I have tried to set one of the fields such as the invoice number as "required". However, when I do this, if the user gets called away, without entering that required field, she is unable to close the form. This makes sense as the required field has a missing entry.

    My question is this: How would I set the table up so that the form could be closed if incomplete (without storing any date in the source table), and at the same time set one or more fields as "required". I should probably add that the form I am using is set to data entry and not to view existing records.

    Can I set up the form (using a button and macro perhaps) where the record fields are only saved after it has been completely entered?

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Make a Cancel button which undoes what they have entered in thus far.
    See here, especially the last comment: https://access-programmers.co.uk/for...ad.php?t=14909

  3. #3
    Beginner72 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2016
    Posts
    12
    To elaborate a little bit further, every time the form is opened a record is generated with an auto numbered ID field in the underlying table. If no fields get entered into the form and the form window is closed. The entry (with just an auto numbered ID field) is still stored in the table. How would I set up the form so nothing gets saved to the table until the last field or a certain field is entered? I hope this makes sense.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The quickest and easiest way is to run a delete query in the OnClose event of the form.

  5. #5
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    The quickest and easiest way is to run a delete query in the OnClose event of the form.
    I guess it depends on how you want to handle it. If you want to add a Cancel button, and leave it up to the users to use that to exit without saving changes, using the link I sent, all need is a Cancel button with this one-line of code attached to it:
    Code:
    Private Sub cmdCancel_Click()
        Me.Undo
    End Sub
    That is pretty simple.

    However, if you don't want to leave it up to the users, then using a Delete Query is probably the way to go.

    How would I set up the form so nothing gets saved to the table until the last field or a certain field is entered? I hope this makes sense.
    You would actually make the form an unbound form, and then when they finish, they can click a button to submit it. And behind the button would be an INSERT INTO query that you build from their selections to add the new record to your table. Bear in mind that if you have any validation rules, you might have to create them via VBA code since your fields are not linked to fields in a table with rules.
    As you can see, this way is a bit more work, and I usually avoid it if possible (and use one of the other two suggestions we gave you).

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

Similar Threads

  1. Replies: 7
    Last Post: 03-07-2017, 12:54 PM
  2. Replies: 4
    Last Post: 09-08-2016, 06:35 AM
  3. empty a table/delete all records
    By Jen0dorf in forum Access
    Replies: 3
    Last Post: 02-22-2016, 02:53 PM
  4. Replies: 10
    Last Post: 05-20-2015, 10:30 AM
  5. Replies: 1
    Last Post: 07-29-2014, 04:58 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