标题:DataGrid1_RowColChange 越界问题
只看楼主
wangdi_2022
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2022-11-26
结帖率:60%
已结贴  问题点数:20 回复次数:2 
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编辑过]

搜索更多相关主题的帖子: If Sub Value Text End 
2022-12-27 20:42
mrexcel
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:125
专家分:480
注 册:2022-11-3
得分:14 
哪一句报错?上传个附件好些
2022-12-27 23:11
wangdi_2022
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2022-11-26
得分:0 
2022-12-28 08:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-511013-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.116243 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved