Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why do I have to press enter twice to update a bounded datagrid? 1

Status
Not open for further replies.

hoggle

Programmer
Jul 13, 2001
124
US
I have a datagrid (dgReports) which is bound to an ado (adoProductionReports) control. I have certain columns that can be edited. On my datagrid's keypress event I check for the "enter" key and if that is pushed I update my database.
like this:

Private Sub dgReports_KeyPress(KeyAscii As Integer)
'check if enter has been pressed and update recordset...
If KeyAscii = 13 Then
Me.adoProductionReports.Recordset.Update
End If
End Sub

After the update event has completed I catch the event and update several other tables in my database. Like this:

Private Sub adoProductionReports_RecordChangeComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'print out 3 copies of report
Select Case adReason
Case adRsnUndoAddNew, adRsnUndoUpdate, adRsnFirstChange
'do nothing
Case Else
msgbox "update complete"
End Select
End Sub

now my question is...I have to press enter twice to see the update complete msgbox, why is that? I want to have my users just have to push enter once and it will update...and then run my other updates which replaces that msgbox.

I'm using ado 2.6 and vb6

thanks for any insight
 
remove this:

adRsnFirstChange

Or change the code to this:

Select Case adReason
Case adRsnUpdate, adRsnDelete, adRsnAddNew
msgbox "update complete"
End Select

The ADO events may fire more that once - once for each step of a certain process. You want to catch the last step taken when updataing.


 
I changed my code and I still had to press enter twice to trigger the adRsnUpdate event, so I just decided to throw on an update button and do everything from there, but your code helped me realize what was going on thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top