• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 53
  • Last Modified:

Editing Record not updating in Access

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
gsilouisvilleic
Asked:
gsilouisvilleic
  • 2
2 Solutions
 
PatHartmanCommented:
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
 
Antonio Salva RipollCommented:
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
 
Antonio Salva RipollCommented:
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
 
gsilouisvilleicAuthor Commented:
thank you so much guys
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now