Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a programming code Assume that you have a Microsoft Access database with a

ID: 664672 • Letter: W

Question

Write a programming code

Assume that you have a Microsoft Access database with a table called, Contacts. Assume that the table has these 4 fields:

FirstName
LastName
Phone
Email

Write a VBA procedure that will open the table, add a new record, and fill in the new record with these values:

FirstName = "Martin"
LastName = "Smith"
Phone = "776-321-0985"
Email = "martin.smith776@gmail.com"

Do not use any SQL statements to do this. Only use DAO methods. To help you figure this out you should Google for how to write an Access VBA Sub to add a table record using DAO.

Explanation / Answer

1.Create a Command button.

2.Modify name to cmdAddNewContact

3. Double click on the button and type the following code in the click event:

          Private Sub cmdAddNewContact_Click()
          Dim dbContact As DAO.Database
          Dim rstContact As DAO.Recordset

          Set dbContact = CurrentDb
          Set rstContact = dbContact.OpenRecordset("Contacts")

          rstContact.AddNew
          rstContact("FirstName").Value = "Martin"
          rstContact("LastName").Value = "Smith"
          rstContact("Phone").Value = "776-321-0985"
          rstContact("Email").Value = "martin.smith776@gmail.com"
          rstContact.Update
          End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote