How to create a comment box with time and date stamp in Access

随声附和 提交于 2019-12-13 05:17:26

问题


There's a template in Access 2010 called Contacts. On the form there's a comment box, a text box below it and a button. When you enter text into the text box and click the button it adds the text to the comment box and time/date stamps it. If you do it again it preserves the old text in the comment box and adds the new text below it.

I'm pretty new to access, but I would like to be able to add this feature to my database.

So I've got a Memo field on the table and form and an input text box and button on the form. Does anyone know what I do from here to get that functionality?


回答1:


Here is another example of how to do it. I have the following form:

With the following code:

Private Sub cmdAppendComment_Click()
  If (IsNull(txtNewComment.value)) Then
    MsgBox ("Please enter a comment before clicking" & _
            "on the Append Comment button.")
    Exit Sub
  End If

  If (IsNull(txtComment.value)) Then
    txtComment.value = txtNewComment.value & " ~ " & _
               VBA.DateTime.Date & " ~ " & VBA.DateTime.Time
  Else
    txtComment.value = txtComment.value & _
               vbNewLine & vbNewLine & _
               txtNewComment.value & " ~ " & _
               VBA.DateTime.Date & " ~ " & VBA.DateTime.Time
  End If

  txtNewComment.value = ""
End Sub

What this does is verify that the New Comment has something in it. If so, then it checks the Comment to see if it already contains something. If it does, then it appends the new comment to it, else it just assigns the new comment to it. The date and time is added to the end of each comment.




回答2:


Figured out I had to use the On_Click property of the button and add VBA code to it.

Private Sub cmdAddNote_Click()
 Dim MyDate As String

 MyDate = Now()


 Form_ClientF.txtNotes = vbCrLf + MyDate + vbCrLf + vbCrLf + Form_ClientF.txtAddNote + vbCrLf + vbCrLf + Form_ClientF.txtNotes

 Form_ClientF.txtAddNote = ""

End Sub


来源:https://stackoverflow.com/questions/19161364/how-to-create-a-comment-box-with-time-and-date-stamp-in-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!