Search code examples
ms-accessvbaform-submitms-access-2003

VBA Access New Record When Submitting Form


I'm working on a form that contains 6 fields, and all must be filled out before the form is submitted and a new record is created. Instead of loading a form with each field hardcoded to show up blank, I used:

Private Sub Form_Load()

DoCmd.GoToRecord , , acNewRec
Me.Username = CreateObject("WScript.Network").Username

End Sub

This begins the new record, but when a user closes without finishing the form it creates a incomplete record and throws.

How can I have that line deleted if a user closes with an incomplete form? Or should I only create a new record when a user submits and all fields match a criteria? What is the best practice here?

Thanks in advance.


Solution

  • The simplest and most efficient option is to properly set the fields properties in the underlying table:
    - set the Required property to True,
    - and the Allow zero length property to False.
    No programming required, and will apply to other interfaces you build later as well.