对象打开时不允许操作解决方案

对象打开时不允许操作
对象打开时不允许操作解决方案
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