當我開啟某一筆記錄修改後,按儲存,卻沒將修改後的資料儲存,找了老半天,覺得不可能是Recordset的問題,
覺得可能是因為MaskEdBox的問題,但....又找不出錯誤在哪??實在很頭痛ㄋㄟ!!
麻煩各位前輩指導我一下....very thanks
Private Sub Form_Load()
    Set RstLis = New ADODB.Recordset
    RstLis.CursorLocation = adUseClient
    strSQL = "select * from layout_work_list where project_id='" & frmProject.Text1(1).Text & "'"
    RstLis.Open strSQL, Cnn, adOpenDynamic, adLockPessimistic
  
    Set Me.txtPro.DataSource = RstLis
    Me.txtPro.DataField = RstLis.Fields(0).Name
   
    For i = 0 To 9
      Me.MaskEdBox1(i).Mask = "####/##/##"
      Me.MaskEdBox1(i).AutoTab = True
      Set Me.Text2(i).DataSource = RstLis
      Me.Text2(i).DataField = RstLis.Fields(i + 1).Name
    Next
   
    Set Me.txtMark.DataSource = RstLis
    Me.txtMark.DataField = RstLis.Fields(11).Name
    
  If RstLis.RecordCount = 0 Then
    RstLis.AddNew
    Me.txtPro.Text = frmProject.Text1(1).Text
  End If
  
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   If RstLis.EditMode = adEditAdd Or RstLis.EditMode = adEditInProgress Then '沒按儲存即離開,editmode怎麼會等於0 呢??
    strSQL = MsgBox("紀錄已修改,是否保存?", vbQuestion + vbYesNoCancel, "")
    If strSQL = vbYes Then
      Call cmdSave_Click
      Cancel = False
    ElseIf strSQL = vbNo Then
      Cancel = False
    Else: Cancel = True
    End If
  End If
  
End Sub
Private Sub cmdSave_Click()
RstLis.Update
End Sub
Private Sub MaskEdBox1_GotFocus(Index As Integer)
If IsDate(Me.Text2(Index).Text) Then
      Me.MaskEdBox1(Index).Text = Format(Me.Text2(Index).Text, "yyyy/mm/dd")
     Else: Me.MaskEdBox1(Index).Text = "____/__/__"
     End If
    
  Me.Text2(Index).Visible = False

Me.MaskEdBox1(Index).SelStart = 0
  Me.MaskEdBox1(Index).SelLength = Len(Me.MaskEdBox1(Index).Text)
  
End Sub
Private Sub MaskEdBox1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
    SendKeys "{tab}"
  End If
  
End Sub
Private Sub MaskEdBox1_Validate(Index As Integer, Cancel As Boolean)
If Me.MaskEdBox1(Index).ClipText = "" Then
    Me.Text2(Index).Text = ""
    Me.Text2(Index).Visible = True
  Else
    If IsDate(Me.MaskEdBox1(Index).FormattedText) Then
     Me.Text2(Index).Text = Me.MaskEdBox1(Index).FormattedText
     Me.Text2(Index).Visible = True
    Else: MsgBox "輸入錯誤"
       Me.MaskEdBox1(Index).SelStart = 0
       Me.MaskEdBox1(Index).SelLength = Len(Me.MaskEdBox1(Index).Text)
       Cancel = True
    End If
   
  End If
    
End Sub
Private Sub Text2_GotFocus(Index As Integer)
Me.MaskEdBox1(Index).SetFocus
    Me.Text2(Index).Visible = False

End Sub
Private Sub Text2_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
    SendKeys "{tab}"
  End If
  
End Sub
Private Sub txtMark_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
    SendKeys "{tab}"
  End If
  
End Sub
arrow
arrow
    全站熱搜

    vbqa 發表在 痞客邦 留言(0) 人氣()