Hi all.
I could really need some help here...
I just cannot figure out why the last record in a do while loop does not get updated.
Background:
Sql Server backend, connection string - not linked tables.
The records I want to be updated are selected in a form with one check box on each row (CableMarked - part of criteria below)
Then, a button on the form runs some queries to get the wanted values to some variables, (tmpFromTag and tmpFromText) and finally run this code:
rsUpd.Open "SELECT * FROM " & tmpCableTable & " WHERE <long series of criteria I know works 100%> ORDER BY CableID", gConn, adOpenStatic, adLockOptimistic
If Not (rsUpd.BOF And rsUpd.EOF) Then
rsUpd.MoveFirst
Do While Not rsUpd.EOF
tmpCableID = rsUpd!CableID 'thesse two line just to see if records are found
MsgBox "Cable ID: " & tmpCableID
cmd.CommandText = "UPDATE " & tmpCableTable & " SET FromTag = '" & [tmpFromTag] & "', " _
& "FromText = '" & [tmpFromText] & "', " _
& "CableMarked = ? " _
& "CableLocalID = '" & "" & "', " _
& "CableMarked = ? " _
& "WHERE SystemID = '" & [tmpSystemID] & "' And CableMarked <> 0 And CableLocalID = '" & [tmpUserID] & "' AND ProjectNo = '" & [tmpProjectNo] & "'"
cmd.CommandType = adCmdText 'The criteria abowe is the same as used u\in rsUpd.Open
cmd.Parameters.Append cmd.CreateParameter("CableMarked", adBoolean, adParamInput, , tmpMarked)
cmd.Execute
cmd.Parameters.Delete 0
rsUpd.MoveNext
Loop
End If
rsUpd.Close
When this code run, it will skip the last record. I've tried with 2, 3, 5 or 10 record, the last one is skipped. Alle data is saved correctly, but not on the last one
I've also tried this code with 'remmed out' everything related to cmd. (all updateing exluded, just running through all record in criteria) so the criteria CableLocalID and CableMarked is not changed - to avoid to do anything with the criteria in rsUpd.open or in cmd.Commandtext. - no difference.
Also need to mention that I've also have tried with update the recordset with rsUpd!fields = values and rsUpd,Update - version with no better resutl I believe it's nothing about the saving of data because it skips the last record without any type of updating of data involved.
I've also tried with Do Until loop, with the rsUpd.MoveFirst removed, and all other trix I've found so far, but with no luck.
I've got 'totally blind' on this case, so I hope someone can help me pinning out where I'm doing something wrong.
Btw; the original code worked perfectly with linked tables, but my organization 'force' med to use connection to server without linking due to security reason,,,
Thank you!
Best regards, Geirr.
I could really need some help here...
I just cannot figure out why the last record in a do while loop does not get updated.
Background:
Sql Server backend, connection string - not linked tables.
The records I want to be updated are selected in a form with one check box on each row (CableMarked - part of criteria below)
Then, a button on the form runs some queries to get the wanted values to some variables, (tmpFromTag and tmpFromText) and finally run this code:
rsUpd.Open "SELECT * FROM " & tmpCableTable & " WHERE <long series of criteria I know works 100%> ORDER BY CableID", gConn, adOpenStatic, adLockOptimistic
If Not (rsUpd.BOF And rsUpd.EOF) Then
rsUpd.MoveFirst
Do While Not rsUpd.EOF
tmpCableID = rsUpd!CableID 'thesse two line just to see if records are found
MsgBox "Cable ID: " & tmpCableID
cmd.CommandText = "UPDATE " & tmpCableTable & " SET FromTag = '" & [tmpFromTag] & "', " _
& "FromText = '" & [tmpFromText] & "', " _
& "CableMarked = ? " _
& "CableLocalID = '" & "" & "', " _
& "CableMarked = ? " _
& "WHERE SystemID = '" & [tmpSystemID] & "' And CableMarked <> 0 And CableLocalID = '" & [tmpUserID] & "' AND ProjectNo = '" & [tmpProjectNo] & "'"
cmd.CommandType = adCmdText 'The criteria abowe is the same as used u\in rsUpd.Open
cmd.Parameters.Append cmd.CreateParameter("CableMarked", adBoolean, adParamInput, , tmpMarked)
cmd.Execute
cmd.Parameters.Delete 0
rsUpd.MoveNext
Loop
End If
rsUpd.Close
When this code run, it will skip the last record. I've tried with 2, 3, 5 or 10 record, the last one is skipped. Alle data is saved correctly, but not on the last one
I've also tried this code with 'remmed out' everything related to cmd. (all updateing exluded, just running through all record in criteria) so the criteria CableLocalID and CableMarked is not changed - to avoid to do anything with the criteria in rsUpd.open or in cmd.Commandtext. - no difference.
Also need to mention that I've also have tried with update the recordset with rsUpd!fields = values and rsUpd,Update - version with no better resutl I believe it's nothing about the saving of data because it skips the last record without any type of updating of data involved.
I've also tried with Do Until loop, with the rsUpd.MoveFirst removed, and all other trix I've found so far, but with no luck.
I've got 'totally blind' on this case, so I hope someone can help me pinning out where I'm doing something wrong.
Btw; the original code worked perfectly with linked tables, but my organization 'force' med to use connection to server without linking due to security reason,,,
Thank you!
Best regards, Geirr.