-
1
- #1
I have a split Access2000 database, and it would appear, as serious problem. The Data is held on a Novell Server. After an import from an ODBC source, which works well, I've had to revert to using code to calculate the discount on the order. The following code works well enough, up to a point, the code then exclaims that <font color=red> Couldn't Update; Currently Locked</font>. <br>I know for a fact that the record is not locked, as there is nothing locking it except for the code below when it's running. The code runs directly after a set of SQL commands which have finished running by the time it gets to this point. What I'm not sure about is if this error is down to the number of records in the recordset, or whether it's a problem caused by a slow server connection.<br><br>Any help would be greatly appreciated.<br><br>The code I'm using is:<br><font color=blue><br>Public Function UpdtDiscount(StrStatus As String)<br>On Error GoTo ErrorBitz<br><br>Dim cnnSEP As ADODB.Connection<br>Dim rstSEP_ALL As New ADODB.Recordset<br>Dim StrSQL As String<br>Dim i As Long<br>Dim RecCount As Long<br>Dim RecNumber As Long<br>Dim CrashTestNo As String<br><br>' Set the local connection<br>Set cnnSEP = CurrentProject.Connection<br>Set rstSEP_ALL = New ADODB.Recordset<br><br>StrSQL = "SELECT * FROM [SEP ALL] WHERE (([Status] = '" & StrStatus & "'));"<br>'now update calculated fields in SEP ALL<br>With rstSEP_ALL<br> RecNumber = 0<br> rstSEP_ALL.Open StrSQL, cnnSEP, adOpenDynamic, adLockOptimistic, adCmdText<br> rstSEP_ALL.MoveLast<br> rstSEP_ALL.MoveFirst<br> CrashTestNo = rstSEP_ALL![Enquiry Number] & " / " & rstSEP_ALL![Enquiry Line Number]<br> RecCount = DCount("[Enquiry Number]", "SEP ALL", "[Status] Is Null or [Status] = ''"
<br> i = SysCmd(acSysCmdInitMeter, "Calculate Discount", RecCount)<br> Do While Not rstSEP_ALL.EOF<br> Select Case rstSEP_ALL![Selling Unit]<br> Case "E"<br> rstSEP_ALL![Discount] = Round(rstSEP_ALL![Amount] * (rstSEP_ALL![Actual Price per Unit] - rstSEP_ALL![System Rec Price per Unit]), 2)<br> Case "L"<br> rstSEP_ALL![Discount] = Round(rstSEP_ALL![Actual Price per Unit] - rstSEP_ALL![System Rec Price per Unit], 2)<br> Case "T"<br> rstSEP_ALL![Discount] = Round(rstSEP_ALL![Total Line Weight kg] * (rstSEP_ALL![Actual Price per Unit] - rstSEP_ALL![System Rec Price per Unit]), 2)<br> Case "M"<br> rstSEP_ALL![Discount] = Round(((rstSEP_ALL![dimension4] * rstSEP_ALL![Amount] * rstSEP_ALL![Actual Price per Unit]) \ 1000) - ((rstSEP_ALL![dimension4] * rstSEP_ALL![Amount] * rstSEP_ALL![System Rec Price per Unit]) \ 1000), 2)<br> Case Else<br> rstSEP_ALL![Discount] = 0<br> End Select<br> .Update<br> .MoveNext<br> RecNumber = RecNumber + 1<br> i = SysCmd(acSysCmdUpdateMeter, RecNumber)<br> Loop<br> rstSEP_ALL.Close<br>End With<br>cnnSEP.Close<br>Set rstSEP_ALL = Nothing<br>Set cnnSEP = Nothing<br><br>i = SysCmd(acSysCmdRemoveMeter)<br><br>Err_Continue:<br>Exit Function<br><br>ErrorBitz:<br> MsgBox "An error has occurred whilst calculating discount for Status = " & _<br> StrStatus & Chr(10) & Chr(10) & _<br> "Please report the following message to Help Desk"<br> MsgBox "Failed on Enquiry: " & CrashTestNo<br> MsgBox Err.Description<br> DoCmd.SetWarnings False<br> DoCmd.RunSQL ("UPDATE Source SET Source.[Allow Imports] = True, Source.Username = '';"
<br> DoCmd.SetWarnings True<br> Resume Err_Continue<br><br>End Function<br></font><br>