datagrid控件中写入记录提示错误,高手帮帮忙
本帖最后由 bcrun 于 2013-06-30 22:04:46 编辑 在一个表单中,一个按钮中的代码
Adodc1.RecordSource = "SELECT * FROM HT_cpmxls WHERE CREATOR='" & LoadPeople & "' "
Set DataGrid1.DataSource = Adodc1
Adodc1.Refresh
DataGrid1.Refresh
DataGrid1.AllowAddNew = True
DataGrid1.AllowDelete = True
DataGrid1.AllowUpdate = True
此时直接在datagrid1中增加记录,增加记录的要求是每增加一行,在第一列和最后一列自动赋值,并且这两列是不可更改的,第一列为序号,最后一列为登陆人
当增加到第十条记录时在”DataGrid1.Row = Adodc1.Recordset.RecordCount - 1“这一行提示我
”当前事件句柄仍在运行时,请求无法被执行“
Private Sub DataGrid1_AfterInsert()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
'计算序号值
sql = "SELECT max(CPMX002) AS MAXXH FROM HT_cpmxls WHERE CREATOR='" & LoadPeople & "'"
rs.Open sql, ADOCN, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
XH = rs("MAXXH") + 1
Else
XH = "0001"
End If
If Adodc1.Recordset.RecordCount > 1 Then
DataGrid1.Row = Adodc1.Recordset.RecordCount - 1
End If
’写入第一列和最后一列
DataGrid1.Columns(9).Text = LoadPeople
DataGrid1.Columns(0).Text = Format(XH, "0000") 'DataGrid1.Count
DataGrid1.Refresh
End Sub