Link to home
Start Free TrialLog in
Avatar of chobe
chobe

asked on

Editing a existing record

I use a datasheet to list projects.  Clicking on project ID opens form with selected record.  Allow Edits = Yes, Data Entry = No, Record Locks = Edited Record.  When I first saved edited record, changes were saved to first record in table, not correct record.  So added RS.FindFirst "ProjectID = " & me.txtProjectRecordNumber.  Then started getting Runtime error 3188 Could not update; currently locked by another session.  I thought the original open datasheet might be the culprit so I added code to close the datasheet after the form opens - same error.  Next I tried adding a line in the code to change the recordlocks to 0 (Forms("tblProjectControl").RecordLocks=0) which solved the issue with the locked form but this refreshes the form (calls CurrentForm) and causes lots of other problems.  How can I fix?
Dim DB As DAO.Database
    Dim rst As DAO.Recordset
    Set DB = CurrentDb
    Set rst = DB.OpenRecordset("tblProjectControl")
    With rst
        .FindFirst "ProjectID = " & Me.txtProjectNumber
        .Edit
        !RequestDT = Me.txtRequestDT
        !RequestHR = Me.txtRequestTime
        !Insert_User = Me.txtGetUser
        !ImpactnoAction = Me.txtImpactnoAction
        !Justification = Me.txtJustification
        ...
        .update
        .close
        Set rst=nothing
    End With

Open in new window

Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Why are you opening the second form at all?
Since you are editing the matching record in code there appears to be no obvious reason to open the from.

If you really need to open the second form, then run the 'editing' code from your post first and then open the form.
This sort of problem is lot easier to diagnose with a database to work on.  Is there any chance you could post a cutdown sample database that exhibits the behaviour you are describing?
Avatar of chobe
chobe

ASKER

To provide a sample database would be impractical because of the number of subforms number of tables, etc.  As to why I need two forms; Each record has some 70+ fields so editing in a datasheet is way to cumbersome.  The first form provides only a few identifying fields such as project ID, name, current project manager, etc., for some 900 records.  That's why I need the two forms - first to select the record and second to display and edit the record.  I have since discovered that if I remove the statement rst.findfirst "ProjectID = " * me.txtProjectNumber, that it not appears to work as expected - saving the changes to the same record as in the form but I'm concerned that things will break down and start saving changes the the first record again.  I appreciate any assist you can think of....
Avatar of chobe

ASKER

O.K. at least now I better understand the issue.  My code opens a NEW recordset in addtion to the forms recordset.  Thus the reason for the locked issues.  Question is how do I update the forms recordset?
If you are going to leave the form open fore the user to do more input then you could write to the form controls instead.  Or as I said before, complete the code  updates to the table first and then open the form.
ASKER CERTIFIED SOLUTION
Avatar of chobe
chobe

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