Private Sub Form_Load() AppDisk = Trim(App.Path) If Right(AppDisk, 1) <> "\" Then AppDisk = AppDisk & "\" Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AppDisk & "bwscale.mdb;Persist Security Info=False" Adodc1.RecordSource = "select * from bwmain" Set DataGrid1.DataSource = Adodc1 End SubPrivate Sub DataGrid1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveFirst End If End If End Sub
datagrid中如果存在上下滚动条的时候会出现这个错误 “行无效”,有可能不是你代码问题。
不知道楼主完整代码是怎么写的 我创建个数据穿体 在里面加上了 'adodc1.connectionstring="PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=temp.mdb;" 'adodc1.RecordSource="select * from temptb" 'datagrid1.datasourec=adodc1 Private Sub DataGrid1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then _ DataGrid1.Row = DataGrid1.Row + 1 End If 确实没报错
呵呵 我是说上面那段 select case 先不说他 select啥 在select下面加个if立马报错下面这段 Private Sub DataGrid1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then _ DataGrid1.Row = DataGrid1.Row + 1 End If你多按几次回车看错不错?
AppDisk = Trim(App.Path)
If Right(AppDisk, 1) <> "\" Then AppDisk = AppDisk & "\"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AppDisk & "bwscale.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from bwmain"
Set DataGrid1.DataSource = Adodc1
End SubPrivate Sub DataGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Not Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveFirst
End If
End If
End Sub
我创建个数据穿体 在里面加上了
'adodc1.connectionstring="PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=temp.mdb;"
'adodc1.RecordSource="select * from temptb"
'datagrid1.datasourec=adodc1
Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then _
DataGrid1.Row = DataGrid1.Row + 1
End If
确实没报错
先不说他 select啥 在select下面加个if立马报错下面这段
Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then _
DataGrid1.Row = DataGrid1.Row + 1
End If你多按几次回车看错不错?
按多少次都没事
绝对不会出现这种情况的
addnew第一次后 焦点会出现在fields(0)上 在update之前是不会下一个addnew的
只要addnew=true update=false 就绝对不回出问题
在新记录行是禁止输入的