Question : Access ADP / SQL 2008 locking records

I have an access adp database which is linked to sql 2008

I have 2 different lists on 2 different forms which read the same data. I have the attatched code on the double click event of this list.

The code all works fine however on the code attatched and a similar code on another form, when the person tries to move to another record they get the message box about another user editing data. Normally they can click save and it will work, however sometimes they can keep clicking save a dozen times and nothing will happen.

is there a way to stop this from happening? I asked around the building about some of the records and other people said they were not in it at the same time only earlier on in the day.

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
userip = MsgBox("Do you want to enter a MID for the following Agreement " & vbNewLine & vbNewLine & "Legal Name         -      " & Me.List359.Column(2) & " " & vbNewLine & "Trading as Name -      " & Me.List359.Column(3) & vbNewLine & vbNewLine & " This will mark the agreement as approved and enable it for E-Delivery", vbYesNo)
If userip = 6 Then
Dim sqlmid As String
Dim sqlmidcheck As String
Dim amexmid As String
Dim sqltemp As String
Dim inputdate As String
Dim datetoday As String
 
datetoday = Format(DateTime.Now, "yyyy-mm-dd hh:mm:ss")
datetoday = datetoday & ":000"
 
 
    sqlmid = InputBox("Please Please enter a MID Number", "New MID")
    
    If Len(sqlmid) = 8 Then
    sqlmidcheck = InputBox("Please Confirm that the MID number " & sqlmid & " is corret", "Confirm MID")
        If sqlmid = sqlmidcheck Then
        sqltemp= "111"
        CurrentProject.Connection.Execute _
        "Update [v_sentto] Set [v_sentto].[MID] = '" & sqlmid & "' where [v_sentto].Auto = '" & Me.List359.Column(0) & "'"
enteramexmid:
        userip = MsgBox("Would you like to enter an AMEX MID for this agreement?", vbYesNo)
            If userip = 6 Then
            amexmid = InputBox("Please enter an AMEX MID (10 Charachters)", "AMEX MID")
                If Len(amexmid) = 10 Then
                sqltemp = "123"
                CurrentProject.Connection.Execute _
                "Update [v_senttosms] Set [v_senttosms].[AMEX MID] = '" & amexmid & "' where [v_senttosms].Auto = '" & Me.List359.Column(0) & "'"
                Else
                MsgBox "Amex MID's MUST be 10 Charachters long. Please Re-Enter the Amex MID"
                GoTo enteramexmid
                End If
            End If
            CurrentProject.Connection.Execute _
            "Update [v_sentto] Set [v_sentto].[Date Approved / Declined] = '" & datetoday & "' where [v_sentto].Auto = '" & Me.List359.Column(0) & "'"
            CurrentProject.Connection.Execute _
            "Update [v_sentto] Set [v_sentto].[Hypercom Template] = '" & hypercomtemplate & "' where [v_sentto].Auto = '" & Me.List359.Column(0) & "'"
            CurrentProject.Connection.Execute _
            "Update [v_sentto] Set [v_sentto].[PrintConf] = 'Yes', [v_sentto].[PrintWelcome] = 'No' where [v_sentto].Auto = '" & Me.List359.Column(0) & "'"
            CurrentProject.Connection.Execute _
            "Update [v_sentto] Set [v_sentto].[Internal Status] = 'Approved' where [v_sentto].Auto = '" & Me.List359.Column(0) & "'"
                  
            MsgBox "MID            - " & sqlmid & vbNewLine & vbNewLine & " AMEX MID - " & amexmid & vbNewLine & vbNewLine & " has been entered for '" & Me.List359.Column(2) & "'"
        Else
        MsgBox "The MID's did not match, please try again."
        End If
    Else
    MsgBox "a MID must be 8 characters long. Please re-enter the mid Correctly"
    End If
Else
MsgBox "MID has not been updated"
End If
 
Me.List359.Requery

Answer : Access ADP / SQL 2008 locking records

My recommendation would be to use a SQL stored procedure. Collect and verify all input data, then execute your stored procedure. In the stored procedure use a transaction to make sure all the updates are executed in one swoop. Your code does not guarantee that another user is updating the data concurrently...

Regards

Felix Burkhard
Random Solutions  
 
programming4us programming4us