Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timestamp in field

Status
Not open for further replies.

patrichek

MIS
Nov 18, 2003
632
US
Hi,
I have a form with a notes section and I'd like to have a time and date stamp automatically inserted when a user inputs notes. This would have to happen if someone adds notes later on too.
any help is appreciated!
 
Maybe in the AfterUpdate event of the notes section use something like:

txtDate_TimeChanged=Now()


where txtdate_TimeChanged is a txt box that holds the date time. HTH
 
would that record each new note that was added? I mean would there be a date and time for every note?
If i put notes in last friday it needs to show 2:00 pm 11/04/05

then a note for today would read 2:30 p.m. 11/09/05?
 
is there one notes field that you just add to over and over? if there is a note field per record and a "timestamp" field per record, then the previous post should work.
 
yeah, only one notes field adding new notes too, any ideas?
 
Well a guess would be to put similar code in the OnChange event maybe... it will take a little more doing but I think it is doable.
 
If I figure it out I'll post it in this thread.
thanks!
 
if your notes field is part of the same table as the other fields, then the onchange event of the notes should work. If you give us the names of the fields for the table you are working with, we would definitely be able to figure it out.

_______________
[cN]
 
Hi Demann,
there are at least 20 fields on my contacts table. I just named the notes field "notes" and it is part of the same table. The table name is "contacts"

I can list all of them if you'd like?
 
okay, well in that case, if you follow jadams advice, then it should work just fine.

in design view, go to the properties of the notes text box, and click on the button associated with the onChange event for "notes." You should go to code builder, and try that code that jadams suggested.

If your time_date field is called timeChanged, then the following code should work:

[timeChanged]=now()

that should be it, I will test it out here to make sure. This way, whenever you go to a record, you can see the last time someone updated the notes section.

_______________
[cN]
 
Forgive me for jumping in here...but it sounds like you want to insert a time stamp into the Notes memo field anytime you add additional notes and keep a running time stamp for each note. If that is the case play with adding a time stamp in the Got Focus event of your Notes field:

Private Sub Notes_GotFocus()
Dim strNotes As String
If Me.Notes.OldValue <> "" Then
strNotes = Me.Notes.OldValue
Me.Notes = strNotes & vbCrLf & Now() & vbCrLf
Else
Me.Notes = Now() & vbCrLf
End If
End Sub

Just a suggestion...not a perfect way but a way
 
ahhhh, I see. After re-reading it, it does seem like that's what he wants.

With your suggestion, how do you resolve the scenario where someone clicks in the notes field, but doesn't input anything? The Gotfocus event would automatically put in a timestamp as soon as you click, regardless of if you type anything.

(not trying to take anything away from the solution, 'cause it is smooth).

_______________
[cN]
 
i received an "ambigous name" error and had to remove the code in order to continue....
 
DeMann,

Well I guess a work around would be to have the notes control disabled and use a command button to enable the notes control and move the focus to it. That would avoid the issue I guess. Otherwise you would just back space the time stamp out if you entered the control by mistake. There really wasn't any security with it anyway. In my own applications I use a separate text box to store the time stamp that the user can't change...albeit they could manage to do it if they really wanted too...<g>

patrichek...are you using DAO references?
 
Ok Patrichek see how this works.

The only way I could do this was to add a popup form to the notes text box. In the On Double Click event like this:
Code:
Private Sub Text2_DblClick(Cancel As Integer)
DoCmd.OpenForm "frmpopnotes"
End Sub

Where Text2 is you notes text box. Make frmpopnotes a MODAL, POPUP form in the forms properties. This will make it stay on top of the main form. In the popup form put this code:
Code:
Private Sub txtnotespopup_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then
Forms!form1!Text2 = Forms!form1!Text2 & txtnotespopup & " " & Now & vbCrLf
txtnotespopup = ""
End If
End Sub

The KeyAscii=Asc(UCase(Chr(keyascii))) line make all the letters uppercase when they are typed. (Something I like) You can take this line out if you want to. When the user press ENTER (KeyAscii=13) then take the old notes and add the new note and the date/time.

I still have my test database if you want it I'll email it to you and you can see how it works. HTH
 
Hi guys,
thanks for all the responses!

I think i will change the format of the notes where a date and time stamp will be applied and each new note will be a new record rather than trying to clump them all in one field. spitzofl's suggestion above.
This forum is most helpful and I don't know where I'd be without you guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top