DataGrid1_RowColChange 越界问题
Private Sub Combo1_Click()If cn.State = adStateOpen Then
cn.Close
End If
If rs.State = adStateOpen Then
rs.Close
End If
cn.ConnectionString = "driver={SQL Server}; server=work1; uid=sa;pwd=123; database=master"
cn.Open
rs.Open "select * from ypkxxb where 药品类别='" & Combo1.Text & "'", cn, 1, 3
================些处combo1.text有两个选项,中药和西药====================
If rs.EOF Then
Exit Sub
End If
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
If rs.RecordCount > 0 Then
rs.MoveLast
rs.MoveFirst
End If
Me.Text1.Text = Str(rs.RecordCount)
End Sub
当第一次选中combo1时(无论选中药还是西药),DATAGrid1 正常显示内容
Private Sub DataGrid1_Click()
单击一行,把这行的数据同时传给两个form
DataGrid1.MarqueeStyle = dbgHighlightRow
Form8.Text1.Text = DataGrid1.Columns(0).Value
Form8.Text2.Text = DataGrid1.Columns(1).Value
Form8.Text3.Text = DataGrid1.Columns(2).Value
Form8.Text4.Text = DataGrid1.Columns(3).Value
Form8.Text5.Text = DataGrid1.Columns(4).Value
Form8.Text6.Text = DataGrid1.Columns(5).Value
Form8.Text7.Text = DataGrid1.Columns(6).Value
Form8.Text8.Text = DataGrid1.Columns(7).Value
Form8.Text9.Text = DataGrid1.Columns(8).Value
Form8.Text10.Text = DataGrid1.Columns(9).Value
Form8.Text11.Text = DataGrid1.Columns(10).Value
Form8.Text12.Text = DataGrid1.Columns(11).Value
Form8.Text13.Text = DataGrid1.Columns(12).Value
Form8.Refresh
Form13.Text1.Text = DataGrid1.Columns(0).Value
Form13.Text2.Text = DataGrid1.Columns(1).Value
Form13.Text3.Text = DataGrid1.Columns(2).Value
Form13.Text4.Text = DataGrid1.Columns(3).Value
Form13.Text5.Text = DataGrid1.Columns(4).Value
Form13.Text6.Text = DataGrid1.Columns(5).Value
Form13.Text7.Text = DataGrid1.Columns(6).Value
Form13.Text8.Text = DataGrid1.Columns(7).Value
Form13.Text9.Text = DataGrid1.Columns(8).Value
Form13.Text10.Text = DataGrid1.Columns(9).Value
Form13.Text11.Text = DataGrid1.Columns(10).Value
Form13.Text12.Text = DataGrid1.Columns(11).Value
Form13.Text13.Text = DataGrid1.Columns(12).Value
Form13.Refresh
End Sub
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
DataGrid1.MarqueeStyle = dbgHighlightRow
Form8.Text1.Text = DataGrid1.Columns(0).Value
Form8.Text2.Text = DataGrid1.Columns(1).Value
Form8.Text3.Text = DataGrid1.Columns(2).Value
Form8.Text4.Text = DataGrid1.Columns(3).Value
Form8.Text5.Text = DataGrid1.Columns(4).Value
Form8.Text6.Text = DataGrid1.Columns(5).Value
Form8.Text7.Text = DataGrid1.Columns(6).Value
Form8.Text8.Text = DataGrid1.Columns(7).Value
Form8.Text9.Text = DataGrid1.Columns(8).Value
Form8.Text10.Text = DataGrid1.Columns(9).Value
Form8.Text11.Text = DataGrid1.Columns(10).Value
Form8.Text12.Text = DataGrid1.Columns(11).Value
Form8.Text13.Text = DataGrid1.Columns(12).Value
Form8.Refresh
Form13.Text1.Text = DataGrid1.Columns(0).Value
Form13.Text2.Text = DataGrid1.Columns(1).Value
Form13.Text3.Text = DataGrid1.Columns(2).Value
Form13.Text4.Text = DataGrid1.Columns(3).Value
Form13.Text5.Text = DataGrid1.Columns(4).Value
Form13.Text6.Text = DataGrid1.Columns(5).Value
Form13.Text7.Text = DataGrid1.Columns(6).Value
Form13.Text8.Text = DataGrid1.Columns(7).Value
Form13.Text9.Text = DataGrid1.Columns(8).Value
Form13.Text10.Text = DataGrid1.Columns(9).Value
Form13.Text11.Text = DataGrid1.Columns(10).Value
Form13.Text12.Text = DataGrid1.Columns(11).Value
Form13.Text13.Text = DataGrid1.Columns(12).Value
Form13.Refresh
End Sub
不退出当前界面,第二次选中combo1中的另一个选项时,DataGrid1_RowColChange 报错,下标越界。
请问各位,帮帮忙,怎么解决
[此贴子已经被作者于2022-12-27 20:46编辑过]