Solved

Confirm a record has been added MS Access

Posted on 2016-10-11
4
54 Views
Last Modified: 2016-10-11
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.
0
Comment
Question by:dbfromnewjersey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
ID: 41838459
if they are already on a new record, another new record won't be added. You can test if it is on a newrecord by:
if me.newrecord then
   msgbox "This is a New Record"
end if

Open in new window

however, it is a good idea to first save the record before adding one:
if me.dirty then me.dirty = false
if me.newrecord then "You are already on a new record"

Open in new window

0
 

Author Comment

by:dbfromnewjersey
ID: 41838469
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?
0
 
LVL 20
ID: 41838605
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

0
 
LVL 36

Expert Comment

by:PatHartman
ID: 41838662
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?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question