Results 1 to 2 of 2

Thread: VBA Access Form - Saving Blank Records

  1. #1

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    547

    Cool VBA Access Form - Saving Blank Records

    Hi there,

    I've got a form I'm designing in the latest version of Access (2020/2021/O365?) and it's a "continuous" record form.

    Meaning, it's got the built-in controls at the bottom for first, last, next, add new, etc.

    It's mostly a tab-driven form, so, if the user enters data and hits "tab" until a new record is created, it seems as though my database will automatically save that blank record to the database.
    It's a simple form, really, with the form linked to (data record source), one single table.

    I'm attempting to prevent blank records from entering the database but I'm having trouble seeming to get it to do what I need.

    I know I can use VBA in the Form BeforeUpdate event, but I can't seem to get it to trigger correctly / do what I want. There is a "save" button on the form, that performs the DoCmd.Save function, but even if the user blows past this button, it still moves onto creating a new / next / empty record, which is fine. They don't need to save until all records are entered.

    I also am aware that I can put vba code to check for blank fields into my button, but this form is built for speed, so they shouldn't need to actually use the save button until all records are entered.

    How do I do the following:
    1. Before moving to a new record, if the "current" record is blank, do not continue and simply give them an error message and send them back to the blank field
    2. If they partially enter data, but not all of the required fields, ask them, do you want to save? ///THIS SHOULD OVERRIDE THE BLANK DATA REQUIREMENT SO THEY CAN SAVE "IN PROGRESS" ITEMS
    3. Allow for them to start a new record, but if they haven't entered data yet, they *should* be able to move backwards to the previous item on the list, discarding the 'new' record and simply going back one record, without any prompt
    4. If they *tab* into a new record, save the previously entered record, I'm assuming I can just add the DoCmd.Save function here, but perhaps there's a better way?


    Thanks in advance
    *(I've been writing .NET apps for ages now and I've forgotten most of my VBA "intricacies" and "limitations". )


    -Matthew-

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA Access Form - Saving Blank Records

    have a look to see if there is any validation event for the text fields, so any that can't be blank prevent saving
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width