关闭对象后,如何修复此操作

时间:2019-08-29 02:56:27

标签: vb6

列表项

如何解决此错误“关闭对象时不允许进行操作”?

用于在vb6中的列表视图中添加和显示存储的数据

 Dim connect As New ADODB.Connection
  Dim rs As New ADODB.Recordset
  Dim a As Integer
  Dim b As Integer
  Dim x As Long
  Dim c As String
 Option Explicit

  Private Sub Command1_Click()
    rs.AddNew    'this line shows the error
    ado.Recordset.Fields("EMPID").Value = emp.Text
    ado.Recordset.Fields("DEPARTMENT") = Text2.Text
    ado.Recordset.Fields("EMPNAME") = Text1.Text
    ado.Recordset.Fields("TIMEIN") = DTPicker3.Value
    ado.Recordset.Fields("TIMEOUT") = DTPicker4.Value
    ado.Recordset.Fields("LOGDATE") = DTPicker2.Value
    rs.Update

  End Sub

     Private Sub Command2_Click()
           a = DateDiff("d", DTPicker1, DTPicker2)
     b = DateDiff("h", DTPicker3, DTPicker4)

     x = a * b
     c = x * 52.5
     Text7.Text = "Hours:" & x & " Days:" & a & "$ " & c
     End Sub

     Private Sub Form_Load()
      connect.Open _
    "Provider=Microsoft.ACE.OLEDB.12.0;Data 
    Source=C:\Users\MIS02\Desktop\FILE.accdb;Persist Security Info=False"


    With ListView1.ColumnHeaders
    .Add , , "EMPID", Width / 15, lvwColumnLeft
    .Add , , "DEPARTMENT", Width / 10, lvwColumnCenter
    .Add , , "EMPNAME", Width / 12, lvwColumnCenter
    .Add , , "TIMEIN", Width / 12, lvwColumnCenter
    .Add , , "TIMEOUT", Width / 12, lvwColumnCenter
    .Add , , "LOGDATE", Width / 10, lvwColumnCenter
    End With

      End Sub

Sub dbconnection()
connect.Open _
  "Provider=Microsoft.ACE.OLEDB.12.0;Data         
  Source=C:\Users\MIS02\Desktop\FILE.accdb;Persist Security Info=False"

      End Sub
     Sub loaddata()
      Dim list As ListItem
      ListView1.ListItems.Clear
      dbconnection
            rs.Open "Select *from Attendance", con, adOpenDynamic,                  
   adLockOptimistic

      Do Until rs.EOF
      Set list = ListView1.ListItems.Add(, , rs!Employee)
      list.SubItems(1) = rs!Department
      list.SubItems(2) = rs!Surename
      list.SubItems(3) = rs!FirstName
      list.SubItems(4) = rs!TimeIn
        list.Subitems(5)=rs!Timeout
      list.SubItems(6) = rs!DateRecord
      rs.MoveNext


Loop

================================================ ========

我希望我可以在列表视图中存储和显示数据。

1 个答案:

答案 0 :(得分:0)

您将connect声明为连接,并且似乎倾向于使用它(因为您正在调用dbconnection方法)。但是同时,您将con作为打开记录集的参数。该变量可能不存在,或者是否存在于全局级别-未正确初始化/打开。