[英]Update a set of data values using a textbox in a form
我正在使用“多項”表單來顯示查詢中的記錄。
“日期”字段/列為空。
在表單標題上,我使用一個文本框,用戶必須在其中選擇或鍵入日期(默認為日歷)。
在表單標題上還有一個按鈕,我想用它更新所有在 TextBox 中輸入的日期記錄。
我尚未測試的一種方法是讓按鈕運行更新查詢:
UPDATE Table1 SET MyDate = [Forms]![Form1]![MyTextBox]
對理想方法有什么建議嗎?
由於這是 Access,請使用已保存所有記錄的RecordsetClone :
Private Sub YourButton_Click()
Dim Records As DAO.Recordset
Dim NewDate As Date
Set Records = Me.RecordsetClone
If IsNull(Me!MyTextBox.Value) Then
' Nothing to do.
ElseIf Recordset.RecordCount > 0 Then
Records.MoveFirst
NewDate = Me!MyTextBox.Value
With Records
.MoveFirst
While Not .EOF
If DateDiff("d", !MyDate.Value, NewDate) <> 0 Then
' Edit the record.
.Edit
!MyDate.Value = NewDate
.Update
End If
.MoveNext
Wend
.Close
End With
End If
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.