Solved

Editing Record not updating in Access

Posted on 2016-08-26
4
32 Views
Last Modified: 2016-08-30
i made a search bar to look up a record to edit but when i do it only update the first record on the table and not the record iam searching for.  Thank you for the help and here an attachment of the database.
Incident-Report-Database---ASR.accdb
0
Comment
Question by:gsilouisvilleic
  • 2
4 Comments
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 100 total points
Comment Utility
I'm not sure what you are trying to do but F_IncidentCloseForm is bound and so you don't need any of the code you have in savedata1.  All your save button needs to do is to force the save using -
DoCmd.RunCommand acCmdSaveRecord

The reason your code isn't actually updating the correct record is because you are opening a table and simply updating the first record returned in the recordset.  You would need to either open a query with selection criteria or open the table and use the Find method to find the record you want to update.

And one more point - ALWAYS disambiguate DAO objects because if you were to ever have to add a reference to the ADO library, your code would fail or work improperly.

So

Dim rs As DAO.Recordset

is the correct way to dm the object.

A better solution is to simply let Access do its thing.  If all you want the user to update is the Comments field, set the Locked property of all the other controls to Yes and set their tab stops to No so tabbing won't stop in those fields.  I also usually make the backgrounds transparent so the data entry controls show up more easily when not all controls on a form can be updated.  Using this method takes advantage of the power of bound forms and reduces your code to the single save line in the click event of the save button.

OK - one more point.  Column names should contain only the letters a-z and A-Z, the numbers 0-9 and the underscore.  Do not use embedded spaces or special characters.  I prefer to use CamelCase to form my names.  Others prefer the_underscore.
0
 
LVL 2

Expert Comment

by:Antonio Salva Ripoll
Comment Utility
Hi  gsilouisvilleic.

As said @Pat, the table names, column names, form names... must not include spaces o other characters different than letters or numbers and underscore.

I prepared the sample you have posted, based on your original database.
I'll download your modified database, modify it to use CamelCase or underscores, and to accomplish what you are looking for.

Please, let me work on a solution during this weekend.

Best regards.

Antonio. ( Barcelona, Spain)
0
 
LVL 2

Accepted Solution

by:
Antonio Salva Ripoll earned 400 total points
Comment Utility
This expert suggested creating a Gigs project.
Hi  gsilouisvilleic.

I've modified the database, now, the the T_Incident_Table table name and fields are CamelCase mixed with underscores, also I modified the form to use the new names.

First I used F_IncidentCloseForm modifying search form; but latern I thought maybe it would be better to teach you how to use a form for a dual purpose.

And this is what I do, now you have only the F_Incident_Form for the dual purpose, add new incidents and close them.

All this is done via VBA code, so, I think this will teach you how to do things.

Best regards.

Antonio.
Incident-Report-Database---ASR_1.accdb
0
 

Author Closing Comment

by:gsilouisvilleic
Comment Utility
thank you so much guys
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now