Link to home
Start Free TrialLog in
Avatar of Jenkins
JenkinsFlag for United States of America

asked on

Confirm a record has been added MS Access

I have an MS Access database that has a form with an "Add Record" command button.    How can I confirm that a record has actually been added to the table when the button is clicked?  Obviously I can look at the table itself but data entry personally, who will be the ones entering the records once the database is up and running will not. All they will have is the form to look at (with the textboxes for data entry and the command button for adding the records).  I want to ensure when they're doing their data entry that the records are actually being added.  Thank you.
ASKER CERTIFIED SOLUTION
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jenkins

ASKER

I attempted to edit the question but too late.  I wanted to also ask for the code that will actually add the record.  There are 3 textboxes for data entry and a command button. MyTable has 3 fields.  Can I get the code to actually write the data from the textboxes to the table?
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

the form should be bound to the table -- turn on the Property Sheet by right-clicking in Design View and choosing "Properties" from the shortcut menu

click in the upper left, where the rulers intersect, to select the form

on the DATA tab of the Property sheet, choose your table in the Record source property

for each of the controls, on the DATA tab, set the Control Source to the field

here is code I put in a general module to call to add a record:
'~~~~~~~~~~~~~~~~~~~~~~~~~~ RecordNew
Function RecordNew(Optional pF As Form _
   , Optional pFirstControlName As String = "") As Byte
' Crystal (strive4peace)
'3-20-09... 160819
   
   'example useage: Click [Event Procedure] for a New Record command button
   ' Call RecordNew(Me)
   ' RecordNew Me, "Controlname"
   'can also be assigned on the property sheet
   'to make logic copy when buttons are copied
   ' =RecordNew([Form])
   
   'NOTE: specify form parameter for subforms
   
   On Error Resume Next
   'if form reference was not passed, use the active form
   If pF Is Nothing Then Set pF = Screen.ActiveForm
   
   'with the referenced (or active) form ...
   With pF
      'if there have been changes to the current record, save them
      If .Dirty Then .Dirty = False
      DoEvents 'do it now
      On Error GoTo Proc_Err
      'create new record
      If Not .NewRecord Then
         If Not .AllowAdditions Then
            .AllowAdditions = True
         End If
         .Recordset.AddNew
      End If
      'set focus to first control, if specified
      On Error Resume Next
      If pFirstControlName <> "" Then
         .Controls(pFirstControlName).SetFocus
      End If
   End With
   
   DoEvents
   
Proc_Exit:
   On Error Resume Next
   Exit Function
Proc_Err:
   If Err.Number = 2046 Then
      ' already on a new record
      Exit Function
   End If
   MsgBox Err.Description, , _
     "ERROR " & Err.Number & "   RecordNew"
 
   Resume Proc_Exit
   Resume
   
End Function

Open in new window

When you use bound forms, Access handles the details.  It ALWAYS saves dirty records
1) when you move on to a new record
2) when you move from a main form to a subform or vice versa
3) when you close the form
4) when you close the database
5) there are probably other places.   The point is that Access ALWAYS saves the data or if it can't, gives you an error message.

What exactly are you worried about?