Apparently, I need help with ADO record updates in my MS Access 2019 program which uses linked tables to a MySQL database via ODBC.
The following code fails at the .Update and also .MoveNext lines for each record in the recordset. This code works great if I take out the attempt to write a new calculated value to the [linetotal] column in the linked table.
The error msg I get says "The Microsoft Access database engine stopped the process because you and another user are attempting to change the same data at the same time."
Well, there are no other users in this test module I am developing. Just me!
Any ideas where I have errored?
--------------------------------
Private Sub cboVendorPO_Change()
On Error GoTo Err_cboVendorPO_Change
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim intVendor As Long
Dim strName As String
Dim intLineNo As Integer
Dim dblNextLine As Integer
Dim strCurrency As String
Dim strPriceUM As String
Dim dblPriceFactor As Double
Dim intLineZero As Integer
Dim dblLineTotal As Double
Dim dblOrderTotal As Double
dblOrderTotal = 0
dblLineTotal = 0
intNextLine = 0
intLineZero = 0
intLineNo = 0
intVendor = Nz(DLookup("vendor", "venpoheader", "company = '" & lblHiddenCompany.Caption & "' and " & _
"ponumber = " & cboVendorPO))
strCurrency = Nz(DLookup("currency", "venpoheader", "company = '" & lblHiddenCompany.Caption & "' and " & _
"ponumber = " & cboVendorPO))
Me.txtCurrency = strCurrency
strSQL = "select * from venpodetail where company = '" & Me.lblHiddenCompany.Caption & "' and " & _
"status = 'E' and vendor = " & intVendor & " and ponumber = " & cboVendorPO
Set conn = CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open strSQL, conn, adOpenStatic, adLockOptimistic, adCmdText
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
With rs
strPriceUM = Nz(rs!price_um)
dblPriceFactor = 1
If strPriceUM = "C" Then
dblPriceFactor = 0.01
ElseIf strPriceUM = "M" Then
dblPriceFactor = 0.001
End If
dblLineTotal = Round(rs!poqty * rs!price * dblPriceFactor, 2)
dblOrderTotal = dblOrderTotal + dblLineTotal
If dblLineTotal = 0 Then
intLineZero = intLineZero + 1
End If
.Fields("linetotal").Value = dblLineTotal
.Update
intLineNo = intLineNo + 1
.MoveNext
End With
Loop
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
strName = Nz(DLookup("name", "vendormaster", "vendor=" & intVendor))
Me.lblName.Caption = strName
Me.lblVendor.Caption = intVendor
strName = ""
Me.txtOrderTotal = dblOrderTotal
Me.lstDetails.Requery
If intLineZero > 0 Then
MsgBox ("Errors found - " & intLineZero & "line(S) are missing price info.")
Me.txtOrderTotal.BackColor = vbYellow
Else
Me.txtOrderTotal.BackColor = vbWhite
End If
dblNextLine = intLineNo + 1
cboLineNo = dblNextLine
cboPartNo.SetFocus
Exit_cboVendorPO_Change:
Exit Sub
Err_cboVendorPO_Change:
MsgBox Err.description
Resume Next
End Sub
_________
Just need to be able to update each record with the calculated amount. I have researched this extensively in my 4 MS Access books and also online, both here in Stack Overflow and anywhere I could find online.