Search code examples
vbams-accessms-access-2016recordsetrecord-locking

dialog form 's record is locked


I have form (Arzyabi_Tamin_Konande_da) that opens in dialog form by this code:


Me.Form.Dirty = False
Dim ASK As Integer
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
With rs
    .MoveFirst
    Do While Not rs.EOF
        .Edit
        If (!Tahvil_Tmp = True) * (!Az_Tankhah = False) Then
            If DLookup("[Saff_Arzyabi_2]", "Arzyabi_Tamin_Konande_sh", _
                "val([Cod_Tamin_Konande]) = '" & !Cod_Tamin_Konande & "'") = True Then
                DoCmd.OpenForm "Arzyabi_Tamin_Konande_da", acNormal, , "[Cod_Tamin_Konande]=" & !Cod_Tamin_Konande, , acdialog
            End If
        .Update
        .MoveNext
    Loop
end with

but when the form gets open I cant change records, all the record get locked other wise if I open the form in acWindowNormal mode every thing is right

enter image description here

I try to create another query for the loop I use but it's not working.


Solution

  • But why are you using a edit command in the loop that opens that form?

    You have this:

    With rs
        .MoveFirst
        Do While Not rs.EOF
            .Edit       <------ WHY? This does nothing?????? explain!!!
    
            If (!Tahvil_Tmp = True) * (!Az_Tankhah = False) Then
                If DLookup("[Saff_Arzyabi_2]", "Arzyabi_Tamin_Konande_sh", _
                    "val([Cod_Tamin_Konande]) = '" & !Cod_Tamin_Konande & "'") = True Then
                    DoCmd.OpenForm "Arzyabi_Tamin_Konande_da", acNormal, , "[Cod_Tamin_Konande]=" & !Cod_Tamin_Konande, , acDialog
                End If
            .Update
            .MoveNext
        Loop
    End With
    

    So, what does that .Edit command do? All it REALLY does is wind up locking the reocrd, but then that does ZERO value, does nothing of value, and you don't do any edits??? So, why? What is the reason for that .edit command? (except to lock the reocrd!!!).

    Remove that edit command, you are launching some form, and that form should be able to do whatever it likes to do!!!!

    A wild good guess in the dark??

    That code should be this:

    With rs
        .MoveFirst
        Do While Not rs.EOF
            If (!Tahvil_Tmp = True) * (!Az_Tankhah = False) Then
                If DLookup("[Saff_Arzyabi_2]", "Arzyabi_Tamin_Konande_sh", _
                    "val([Cod_Tamin_Konande]) = '" & !Cod_Tamin_Konande & "'") = True Then
                    DoCmd.OpenForm "Arzyabi_Tamin_Konande_da", acNormal, , "[Cod_Tamin_Konande]=" & !Cod_Tamin_Konande, , acDialog
                End If
            .MoveNext
        Loop
    End With
    
    me.Refresh   <---- show any update dated in our form after dialog
                 prompts are done.