View Full Version : Using .UpdateBatch to update several records


MArgente
06-17-2007, 10:54 AM
Hello all,

Can someone enlighten me as to what I'm doing wrong:

Overview:
I have a form where a user enters 2 values. After they enter the 2 values and clicks on a command button, the form's detail becomes visible and several records are displayed (all at the same time, in consecutive rows). I'm using ADO and I'm trying to figure out how to NOT save the changes if the user strays away from the page. This is the code I have so far. I've also tried using transactions (to no avail) but I'd rather not use them.

Private Sub Form_Deactivate()
If rs.State = adStateOpen Then
rs.CancelBatch
rs.Close
End If
End Sub


Private Sub ApproveButton_Click()
On Error GoTo Err_ApproveButton_Click

If Not rs.EOF And Not rs.BOF Then
Response = MsgBox("Are you sure you want to mark the following as approved?", vbYesNo)
If Response = vbYes Then GoTo UpdateApprovals
Else
rs.CancelBatch
End If

Else
MsgBox ("There are no records to be updated.")
End If
Exit Sub

UpdateApprovals:
rs.UpdateBatch
MsgBox ("The approvals were updated.")
Exit Sub

Err_ApproveButton_Click:
MsgBox Err.Description
Exit Sub

End Sub


However, no matter what I do, the items are still updated (which I know is a characterestic of ADO). Any suggestions?

Thank you.

Moniker
06-17-2007, 10:57 AM
Can you not just display the rows of detail data in read-only form? I don't think I'm understanding your issue here. If you don't want the users wandering to other forms while a particular form is open, then set the form's Modal Property to "Yes" and they have to close that form before they can navigate to another form.

MArgente
06-17-2007, 12:16 PM
The thing is, this one form is under a tab control. My big issue is that the recordset is automatically updating the database without going through the rs.updatebatch command. If I go back and try to retrieve the same records, it shows the updated values. I wouldn't want this as a read-only form because some of the fields need to be updated by the user.

Moniker
06-17-2007, 06:10 PM
How are you displaying the data, in a datasheet view? It sounds like a better solution may be to make a look-alike view using form controls (textboxes and such) and you'd lock each field that you don't want them to edit.

MArgente
06-17-2007, 08:37 PM
How are you displaying the data, in a datasheet view? It sounds like a better solution may be to make a look-alike view using form controls (textboxes and such) and you'd lock each field that you don't want them to edit.

No, it's not in a datasheet view. It's in form view. Currently I have 6 fields per record being shown. Four of the fields are locked so they are UN-updatable. The last two fields CAN be updated. Now if a user wants, they should be able to click the respective checkbox. However, if for whatever reason, they dont want the changes committed and just goes onto another form, the changes should be discarded. The only way for the changes to be commited is by clicking 1 button (on the Form Footer) which would update all the records that are shown.