Hi - can someone now help with my latest problem.
Below, is my full code for an update query i'm trying to excecute. Only when it come to actually perform the update (highlighted), i get an error message sayig the recordset is not updatable.
I have checked the connection, where readonly defaults to false and adopenkeyset and adlockoptimistic should allow for updates. The only thing i can think is that it has something to do with the SQL select query.
I am clueless as to how i can overcome this issue?????
Thanks for the help in advance.
OOch
Below, is my full code for an update query i'm trying to excecute. Only when it come to actually perform the update (highlighted), i get an error message sayig the recordset is not updatable.
I have checked the connection, where readonly defaults to false and adopenkeyset and adlockoptimistic should allow for updates. The only thing i can think is that it has something to do with the SQL select query.
I am clueless as to how i can overcome this issue?????
Code:
Sub T2CUpt()
Dim rs As ADODB.Recordset
Dim strOrderQy As String
Dim i As Integer
'create recordset objest
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
strOrderQy = "SELECT A.MeterPointRef, A.SiteRefNum, A.[Confirmation Reference], A.[Contract Num], A.PricesIDNum, A.Price," & _
"A.StandingCharge, A.[Site status], A.[Effective From Date], A.[Ceased Date], A.NA_SOURCE_STATUS, " & _
"a.NA_Ctrt_STATUS " & _
"FROM [A01-NBS_GAS_ROOTDATA_20040923] as A " & _
"GROUP BY A.MeterPointRef, A.SiteRefNum, A.[Confirmation Reference], A.[Contract Num], A.PricesIDNum,A.Price, " & _
"A.StandingCharge, A.[Site status], A.[Effective From Date], A.[Ceased Date], A.NA_SOURCE_STATUS, " & _
"a.NA_Ctrt_STATUS " & _
"ORDER BY A.MeterPointRef, A.SiteRefNum, A.[Confirmation Reference], A.[Contract Num], A.PricesIDNum;"
With rs
.Open strOrderQy, _
CursorType:=adOpenKeyset, _
LockType:=adLockOptimistic
'Call T2CColUpt
Dim F As Boolean
Dim C, C2, M, M2, S, S2 As String
Dim rs2 As Variant
Dim cs As String
Set rs2 = rs.Clone
rs.MoveFirst
rs2.Move 1
Do Until rs2.EOF 'loop from 1st row last row
cs = Nz(rs![NA_Ctrt_STATUS], "")
C = Nz(rs![standingcharge], ""): M = rs![meterpointref]: S = Nz(rs![siterefnum], "") ' store Charge and MeterRef of row 2
C2 = Nz(rs2![standingcharge], ""): M2 = rs2![meterpointref]: S2 = Nz(rs2![siterefnum], "") ' store rs2's refs
If F And ((M <> M2) Or (M2 = rs2.EOF)) And _
(C <> 0.1055 And C <> 0.1056 And C <> 0.1089 And C <> 0.0928 And C <> 0.1193) Then
' f is true and either MeterRef changed or we're in last row, so flag preceding row and set f to false
[COLOR=red yellow]rs![NA_Ctrt_STATUS] = "T2C"
.Update[/color]
Debug.Print rs.GetString
F = False
ElseIf Not F And (M = M2) And C <> C2 And _
(C = 0.1055 Or C = 0.1056 Or C = 0.1089 Or C = 0.0928 Or C = 0.1193) Then ' f is false and Charge changed for same MeterRef, so set f to true
F = True
End If
rs.MoveNext
rs2.MoveNext
' store Charge and MeterRef of current row
Loop ' proceed with next row
rs.Close
Set rs = Nothing
End With
End Sub
Thanks for the help in advance.
OOch