none
vb6 Access2003 recordset的問題 RRS feed

  • 問題

  • 小弟有form 1 , form 2 ,form3

    form1裡面 的button1事件 form2.Show vbModal

    在form2程式開頭宣告了

    Dim MYC1 As New ADODB.Connection
    Dim MYR1 As New ADODB.Recordset


    form2裡面的button1事件 form3.Show vbModal

    在form3程式開頭宣告了

    Dim MYC1 As New ADODB.Connection
    Dim MYR1 As New ADODB.Recordset

    假設form2是員工基本資料,裡面有一個部門可以選擇,因為怕突然有新建的部門還沒被加入,所以form3可以自己1.新增2.刪除3.修改 部門名稱

    form2是員工基本資料裡面有一個datagrid可以show出所有的員工( 也有新增刪除修改功能),可是當我關閉form3的時候回到form2 ,刪除的時候Datagrid1會沒有顯示,可是我設斷點(Set Datagrid.datesource=Rs)又會跑出資料來,我斷點一拿掉,在按一次delete,datagrid資料就全部消失,不過新增修改卻沒有這種問題,

    小弟的新增刪除修改的寫法差不多都是這樣,請問前輩大概是哪裡出錯了

    Private Sub InsertProcess()
    On Error GoTo error1
           
            Dim str As String
            Dim i As Integer
            Dim point As Long
           
            For i = 0 To 2
                If (Text1(i).Text = "") Then
                    MsgBox ("請輸入完整資料")
                    Exit Sub
                End If
            Next
                
           point = MYR.AbsolutePosition
          
           IDoNotIntoFlag = True
          
           If MYR.RecordCount > 0 Then
               
                MYR.MoveFirst
               
                While (MYR.EOF = False)
          
                     str = "" & MYR.Fields("eno")
                   
                     If str = Text1(0).Text Then
                          MYR.AbsolutePosition = point
                          MsgBox "員工編號重複"
                          IDoNotIntoFlag = False
                          Exit Sub
                     End If
                        
                     str = "" & MYR.Fields("CARDNO")
                     If str = Text1(2).Text Then
                          MYR.AbsolutePosition = point
                          MsgBox "卡號重複"
                          IDoNotIntoFlag = False
                          Exit Sub
                     End If
                    
                     MYR.MoveNext
                Wend
           
           End If
          
          
                                                           
                                                           
            MYR.AddNew
            MYR.Fields("ENO") = Text1(0).Text
            MYR.Fields("CNAME") = Text1(1).Text
            MYR.Fields("CARDNO") = Text1(2).Text
            MYR.Fields("DEP") = DepSelect.Text
            MYR.Fields("COSTCENTER") = Text1(3).Text
            MYR.Fields("StarTime") = DTPicker2.value
            MYR.Update
                                                           
                                                           
           IDoNotIntoFlag = False
                  
    error1:
         

          If Err.Number <> 0 Then
              MsgBox Err.Description
              Err.Clear
          End If
         
    End Sub

     

    Private Sub DelProcess()
    On Error GoTo error1
       
        Dim point As Long
        Dim str As String
       
        If MYR.RecordCount <= 0 Then
                MsgBox ("已無資料")
                Exit Sub
        End If
      
        MYR.Delete
        Set DataGrid1.DataSource = MYR
    error1:
          If Err.Number <> 0 Then
              MsgBox Err.Description
              Err.Clear
          End If
       
    End Sub

    Private Sub ModifyProcess()
    On Error GoTo error1
           
            Dim str As String
            Dim i As Integer
            Dim point As Long
           
           
            If MYR.RecordCount <= 0 Then
                MsgBox "已無資料更新"
                Exit Sub
            End If
           
            For i = 0 To 2
                If (Text1(i).Text = "") Then
                    MsgBox ("請輸入完整資料")
                    Exit Sub
                End If
            Next
                
           point = MYR.AbsolutePosition
          
           IDoNotIntoFlag = True
          
           MYR.MoveFirst
          
           While (MYR.EOF = False)
          
                 str = "" & MYR.Fields("eno")
               
                 If (str = Text1(0).Text) And (point <> MYR.AbsolutePosition) Then
                      MYR.AbsolutePosition = point
                      MsgBox "員工編號重複"
                      IDoNotIntoFlag = False
                      Exit Sub
                 End If
                    
                 str = "" & MYR.Fields("CARDNO")
                 If (str = Text1(2).Text) And (point <> MYR.AbsolutePosition) Then
                      MYR.AbsolutePosition = point
                      MsgBox "卡號重複"
                      IDoNotIntoFlag = False
                      Exit Sub
                 End If

                 MYR.MoveNext
           Wend
                                                           
            MYR.AbsolutePosition = point
                                                         
            MYR.Fields("ENO") = Text1(0).Text
            MYR.Fields("CNAME") = Text1(1).Text
            MYR.Fields("CARDNO") = Text1(2).Text
            MYR.Fields("DEP") = DepSelect.Text
            MYR.Fields("COSTCENTER") = Text1(3).Text
            MYR.Fields("StarTime") = DTPicker2.value
            MYR.Update
                                                           
                                                           
            IDoNotIntoFlag = False
                  
    error1:
         

          If Err.Number <> 0 Then
              MsgBox Err.Description
              Err.Clear
          End If
         
    End Sub

     

     

     

     

    2010年10月26日 下午 07:38