title: Access 2010 VBA manually save record
body: <p>an Access question this time. I have a form that is bound to a certain table and I want this form to only allow adding new entries (not editing or deleting) by clicking on a "Save" button. First problem was that the record was updated while editing the textboxes. The Solution I have has several problems</p>
  
  <pre><code>Option Compare Database
  Option Explicit
  
  Private bSaveRecord As Boolean
  
  Private Sub btCreateRecord_Click()
     bSaveRecord = True
     Me.tblUMgmtUser_UserDetailsID.Value = Me.tblUMgmtUserDetails_UserDetailsID.Value
     Me.tbSetUserHashPW = "12312"
     Me.cbSetInitPW = True
     DoCmd.GoToRecord , , acNext
  End Sub
  
  Private Sub btResetRecord_Click()
      ResetRecord
  End Sub
  
  Private Sub Form_AfterUpdate()
      bSaveRecord = False
  End Sub
  
  Private Sub Form_BeforeUpdate(Cancel As Integer)
      If Not bSaveRecord Then
          Cancel = True
          Me.Undo
      End If
   End Sub
  
  Private Sub Form_Load()
      Me.Username.SetFocus
      DoCmd.GoToRecord , , acNewRec
      bSaveRecord = False
  End Sub
  
   Private Sub ResetRecord()
      Dim cControl As Control
  
      bSaveRecord = False
      For Each cControl In Me.Controls
          If cControl.Name Like "Text*" Then cControl = vbNullString
      Next
      Me.cbResponsible.Value = False
      Me.Undo
  End Sub
  </code></pre>
  
  <p>Problem 1: I have to add hidden textboxes to save values to the record I want to be generated automatically</p>
  
  <p>Problem 2: the ID-column counts up every time I open the form, even if I haven't added a record previously</p>
  
  <p>Generally spoken my solution doesn't feel very robust and elegant. Any suggestions are greatly appreciated</p>
  
  <p>Many thanks
  Jon</p>