对象打开时不允许操作
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim i As Integer, j As Integer
'Public Function cnn() As ADODB.Connection '定义函数
'Set cnn = New ADODB.Connection
'返回一个数据库连接
'cnn.Open "rovider=SQLOLEDB.1ersist Security Info=true;User ID=sa;pwd=eisoft;Initial Catalog=LF_DB;data source=ERPSERVER"
'End Function
Private Sub flex1_DblClick()
MSHFlexGridEdit flex1, txtEdit, 32
End Sub
Private Sub flex1_KeyPress(KeyAscii As Integer)
MSHFlexGridEdit flex1, txtEdit, KeyAscii
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = PublicStr
Adodc1.RecordSource = "select * from qcr"
Adodc1.Refresh
Dim i As Integer
'使第一列较窄。
flex1.ColWidth(0) = flex1.ColWidth(0) / 2
'初始化编辑框
txtEdit = ""
flex1.Rows = 2
flex1.Cols = 8
'设置列标头。
s$ = "序号|^条码号 |^工程号 |^图档号 |^板号 |^验退数量 |^验退部门 |^备注 |^ 制程 "
flex1.FormatString = s$
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "new"
Dim lsph As Integer '声明一个整型变量
rs.Open "select * from qcr order by dh", cnn, adOpenStatic
If rs.RecordCount > 0 Then
If Not rs.EOF Then rs.MoveLast
If rs.Fields("dh") <> "" Then
lsph = Val(Right(Trim(rs.Fields("dh")), 4)) + 1
Text1.Text = Format(Date, "yyyymmdd") & Format(lsph, "0000")
End If
Else
Text1.Text = Format(Date, "yyyymmdd") & "0001"
End If
'设置控件有效或无效
Text1.SetFocus
rs.Close
Case "close"
Unload Me
End Select
End Sub
Sub EditKeycode(MSHFlexGrid As Control, Edt As Control, KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 27
Edt.Visible = False
MSHFlexGrid.SetFocus
Case 13
MSHFlexGrid.SetFocus
DoEvents
If MSHFlexGrid.Col < MSHFlexGrid.Cols - 1 Then
MSHFlexGrid.Col = MSHFlexGrid.Col + 1
Else
If MSHFlexGrid.Col = MSHFlexGrid.Cols - 1 Then
MSHFlexGrid.AddItem "", MSHFlexGrid.Row + 1
MSHFlexGrid.Row = MSHFlexGrid.Row + 1
MSHFlexGrid.Col = 1
End If
End If
Case 38
MSHFlexGrid.SetFocus
DoEvents
If MSFlexGrid.Row > MSFlexGrid.FixedRows Then
MSFlexGrid.Row = MSFlexGrid.Row - 1
End If
End Select
End Sub
Sub MSHFlexGridEdit(MSHFlexGrid As Control, Edt As Control, KeyAscii As Integer)
Select Case KeyAscii
Case 0 To 32
Edt = MSHFlexGrid
Edt.SelStart = 1000
Case Else
Edt = Chr(KeyAscii)
Edt.SelStart = 1
End Select
Edt.Move MSHFlexGrid.Left + MSHFlexGrid.CellLeft - 15, MSHFlexGrid.Top + MSHFlexGrid.CellTop - 15, MSHFlexGrid.CellWidth, MSHFlexGrid.CellHeight
Edt.Visible = True
Edt.SetFocus
End Sub
Private Sub txtEdit_KeyDown(KeyCode As Integer, Shift As Integer)
EditKeycode flex1, txtEdit, KeyCode, Shift
End Sub
Private Sub flex1_Gotfocus()
rs1.Open "select * from scandata", cnn, adOpenStatic
If txtEdit.Visible = False Then Exit Sub
flex1 = txtEdit
txtEdit.Visible = flae
If flex1.Col = 4 Or flex1.Col = 5 Or flex1.Col = 6 Then
flex1.TextMatrix(flex1.Row, 5) = Format(flex1.TextMatrix(flex1.Row, 5), "0.00")
flex1.TextMatrix(flex1.Row, 6) = Val(flex1.TextMatrix(flex1.Row, 4)) * Val(flex1.TextMatrix(flex1.Row, 5))
flex1.TextMatrix(flex1.Row, 6) = Format(flex1.TextMatrix(flex1.Row, 6), "0.00")
End If
End Sub
[解决办法]
rs1 有 Open 就要有配对的 Close。
如果 Open 后没有 Close,再次 Open 就会出错。
[解决办法]
在第二次open之前一定要close
直接调试,出错的前一行加来rs1.close就OK
[解决办法]
rs1.Open 下移一行——如果不需要操作(Exit Sub)就不必打开。
rs1.Close 放在 Gotfocus() 的最末。
又:如果 rs1 仅在 Gotfocus() 中调用,就声明在 Gotfocus() 中。
一次性声明所有变量是汇编时代的风格。太 OUT 了!
[解决办法]
if rs.eof and rs.eof
msgbox ....
else
d.open ...
endif
还有,不会是做石材方面的应用吧!??
[解决办法]
if rs1.state<>adstateclosed then rs1.close
rs1.Open "select * from scandata", cnn, adOpenStatic