unable to update from a button

mana

Registered User.
Local time
Today, 00:28
Joined
Nov 4, 2014
Messages
265
hello

i have a button and i have the below codes in it
but i have this erro: could not update currently locked
can you help how i cna corrrect it?
thank you



Code:
Dim fldEnumerator As Object
Dim fldColumns As Object
    
Dim dbs As Database
Dim recs As Recordset
Set dbs = CurrentDb
Set recs = dbs.OpenRecordset("GPD")
Set fldColumns = recs.Fields
    ' Scan the records from beginning to each
    While Not recs.EOF
        ' Check the current column
        For Each fldEnumerator In recs.Fields
            ' If the column is named Title
            If fldEnumerator.Name = "Project Name" Then
                ' If the title of the current record is "Congo"
                If fldEnumerator.Value = Me.Text0 Then
                    ' then change its value
                    recs.Edit
                    recs("[Real date]").Value = Me.Text5
                    recs("[Real date1]").Value = Me.Text28
                    recs("[Real date2]").Value = Me.Text32
                    recs("[Real date3]").Value = Me.Text34
                    recs("[Real date4]").Value = Me.Text38
                    recs("[Real date5]").Value = Me.Text42
                    recs("[Real date6]").Value = Me.Text46
                    recs("[Plan date]").Value = Me.Text2
                    recs("[Plan date1]").Value = Me.Text22
                    recs("[Plan date2]").Value = Me.Text24
                    recs("[Plan date3]").Value = Me.Text26
                    recs("[Plan date4]").Value = Me.Text36
                    recs("[Plan date5]").Value = Me.Text40
                    recs("[Plan date6]").Value = Me.Text44
                    recs.Update
                End If
            End If
        Next
        ' Move to the next record and continue the same approach
        recs.MoveNext
    Wend
    
    
    
 
    
    
Dim fldEnumeratora As Object
Dim fldColumnsa As Object
    
Dim dbsa As Database
Dim recsa As New ADODB.Recordset
recsa.CursorType = adOpenStatic
recsa.CursorLocation = adUseClient
Set dbsa = CurrentDb
Set recsa = dbsa.OpenRecordset("Projects")
Set fldColumnsa = recsa.Fields
    ' Scan the records from beginning to each
    While Not recsa.EOF
        ' Check the current column
        For Each fldEnumeratora In recsa.Fields
            ' If the column is named Title
            If fldEnumeratora.Name = "Project Name" Then
                ' If the title of the current record is "Congo"
                If fldEnumeratora.Value = Me.Text0 Then
                    ' then change its value
                    recsa.Edit
                    recsa("[Real date]").Value = Me.Text5
                    recsa("[Real date1]").Value = Me.Text28
                    recsa("[Real date2]").Value = Me.Text32
                    recsa("[Real date3]").Value = Me.Text34
                    recsa("[Real date4]").Value = Me.Text38
                    recsa("[Real date5]").Value = Me.Text42
                    recsa("[Real date6]").Value = Me.Text46
                    recsa("[Plan date]").Value = Me.Text2
                    recsa("[Plan date1]").Value = Me.Text22
                    recsa("[Plan date2]").Value = Me.Text24
                    recsa("[Plan date3]").Value = Me.Text26
                    recsa("[Plan date4]").Value = Me.Text36
                    recsa("[Plan date5]").Value = Me.Text40
                    recsa("[Plan date6]").Value = Me.Text44
                    recsa.Update
                End If
            End If
        Next
        ' Move to the next record and continue the same approach
        recsa.MoveNext
    Wend
    
    
    
    
    
 
Dim fldEnumeratorb As Object
Dim fldColumnsb As Object
    
Dim dbsb As Database
Dim recsb As New ADODB.Recordset
recsb.CursorType = adOpenStatic
recsb.CursorLocation = adUseClient

Set dbsb = CurrentDb
Set recsb = dbsb.OpenRecordset("Project_management")
Set fldColumnsb = recsb.Fields
    ' Scan the records from beginning to each
    While Not recsb.EOF
        ' Check the current column
        For Each fldEnumeratorb In recsb.Fields
            ' If the column is named Title
            If fldEnumeratorb.Name = "Project Name" Then
                ' If the title of the current record is "Congo"
                If fldEnumeratorb.Value = Me.Text0 Then
                    ' then change its value
                    recsb.Edit
                    recsb("[Real date]").Value = Me.Text5
                    recsb("[Real date1]").Value = Me.Text28
                    recsb("[Real date2]").Value = Me.Text32
                    recsb("[Real date3]").Value = Me.Text34
                    recsb("[Real date4]").Value = Me.Text38
                    recsb("[Real date5]").Value = Me.Text42
                    recsb("[Real date6]").Value = Me.Text46
                    recsb("[Plan date]").Value = Me.Text2
                    recsb("[Plan date1]").Value = Me.Text22
                    recsb("[Plan date2]").Value = Me.Text24
                    recsb("[Plan date3]").Value = Me.Text26
                    recsb("[Plan date4]").Value = Me.Text36
                    recsb("[Plan date5]").Value = Me.Text40
                    recsb("[Plan date6]").Value = Me.Text44
                    recsb.Update
                End If
            End If
        Next
        ' Move to the next record and continue the same approach
        recsb.MoveNext
    Wend
 
You are not closing the previous recordsets when you have finished your updates, assuming that your record sets are pulling in fields from the same tables they will remain locked.
 
how should i close them?
 
After each Wend

Set recs = Nothing

Should do it.
 

Users who are viewing this thread

Back
Top Bottom